for any key? or for a particular key?
you can use something like:
you can use something like:
import socket # then around code where you want to intercept keys: try: myroutine() # call your routine in place of this except (KeyboardInterrupt, SystemExit): print(f'\nKeyboard Interrupt') # Call routine you want to run on keypress here except: # Call routine you want to run on keypress here raise