0

Is there a way to set up my script so that with one push button I can quit() my script? I am trying to fix my script but because I use input simulation I can't do control-D or using mouse clicks.

Thanks!

Michael C
  • 135
  • 1
  • 1
  • 12
  • See also http://stackoverflow.com/questions/292095/polling-the-keyboard-detect-a-keypress-in-python – cdarke Apr 30 '17 at 18:54

1 Answers1

0

Try this:

>>> try:
...     a = raw_input()
... except EOFError:
...     print "Exited"
... 
Exited
>>> 

Use EOFError for control-D, KeyboardInterrupt for control-C.

Ahsanul Haque
  • 10,676
  • 4
  • 41
  • 57
  • I am not sure I understand; wouldn't that work only when the script runs to that point? I am looking for a way to, with one push of a button, terminate a running script, while the script runs in background or when I do whatever else. – Michael C May 01 '17 at 17:31
  • I heard you can "use a thread to listen in the background" ? – Michael C May 01 '17 at 17:33