Skip to content
Advertisement

readkey command in python

I want my Python program to stop and wait until any key is pressed, then to print the key that was just pressed.

It’s like the Pascal’s command key := readkey; writeln(key);.

I’ ve tried yet to use the msvcrt module and the getch command but it didn’ t work. I tried this:

import msvcrt 
s = msvcrt.getch()
print (s)

And it didn’ t wait I pressed a key, it immediately printed b'xff' and it ended the program

I’ m working with python 3.4

Do you know any way to help me ?

Advertisement

Answer

I found out that if I started my .py file from the command line (pythonw) the command msvcrt.getch() didn’ t work but if I save my .py file and I launched it, the command msvcrt.getch() worked correctly !

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement