2

I am not looking for input() or raw_input(). I am looking for what sounds like is available in the msvcrt module, specifically msvcrt.kbhit() and msvcrt.getch(), but am unable to get it working.

I tried example 1, here:

http://effbot.org/librarybook/msvcrt.htm

and the chosen answer here:

Python Windows `msvcrt.getch()` only detects every 3rd keypress?

both of which put me into infinite loops from which I am unable to escape by pressing 'esc' and 'q' respectively.

import msvcrt
while True:
    pressedKey = msvcrt.getch()
    if pressedKey == 'x':    
       break

I would like to avoid downloading and installing new modules, like pyhook suggested below, if possible:

How do I get realtime keyboard input in Python?

Community
  • 1
  • 1
A B
  • 305
  • 2
  • 5
  • 13

1 Answers1

1

I found the answer here: Python kbhit() problems

Basically, you need to run the program from a console window instead of from the IDE (Python in my case).

Community
  • 1
  • 1
A B
  • 305
  • 2
  • 5
  • 13