"Listen" for key press

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gman2k1
    New Member
    • Mar 2007
    • 1

    "Listen" for key press

    I am a python noob and was wondering how to "listen" for a keystroke. In other words, I want a program to run, but when I press a key (a regular key, not Ctrl-C or Ctrl-Break), I want the program to stop. I would like to implement this in a try..except structure.

    If anyone has a code fragment to illustrate, please include that also.

    Thanks...
  • dshimer
    Recognized Expert New Member
    • Dec 2006
    • 136

    #2
    If you happen to be working in windows, check out this documentation for the msvcrt module, I tried this and it seemed to work great. If not there is what seems like a cross-platform getch recipe in the python cookbook, though I haven't tried this one.

    Comment

    Working...