How to do "hit any key" in python?

Viewed 40506

How would I do a "hit any key" (or grab a menu option) in Python?

  • raw_input requires you hit return.
  • Windows msvcrt has getch() and getche().

Is there a portable way to do this using the standard libs?

7 Answers

I implemented it like the following in Windows. getch() takes a one single character

import msvcrt
char = 0
print 'Press any key to continue'
while not char:
    char = msvcrt.getch()

Another option:

import keyboard
print("Press any key to continue")
keyboard.read_key()
print("to be continued...")
Related