Jan-16-2018, 11:36 AM
Infinite loop is usually done with while True:
Capturing a specific key (as opposed to input terminated by the enter key) is tricky in standard console based Python, and varies from platform to platform.
This will work on many systems, but does not catch ctrl alone (usually a modifier key) but I'm sure there is more to termios that would allow you to address that.
Capturing a specific key (as opposed to input terminated by the enter key) is tricky in standard console based Python, and varies from platform to platform.
This will work on many systems, but does not catch ctrl alone (usually a modifier key) but I'm sure there is more to termios that would allow you to address that.
import sys, termios, tty stdinFileDesc = sys.stdin.fileno() #store stdin's file descriptor oldStdinTtyAttr = termios.tcgetattr(stdinFileDesc) #save stdin's tty attributes so I can reset it later try: print('Press any key to exit...') tty.setraw(stdinFileDesc) #set the input mode of stdin so that it gets added to char by char rather than line by line sys.stdin.read(1) #read 1 byte from stdin (indicating that a key has been pressed) finally: termios.tcsetattr(stdinFileDesc, termios.TCSADRAIN, oldStdinTtyAttr) #reset stdin to its normal behavior print('Goodbye!')
I am trying to help you, really, even if it doesn't always seem that way