1

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 ?

VinceLomba
  • 398
  • 2
  • 8
  • 18
  • 7
    possible duplicate of [Python read a single character from the user](http://stackoverflow.com/questions/510357/python-read-a-single-character-from-the-user) – Matt Jul 01 '15 at 09:34
  • That work fine for me - although you might prefer to use: msvcrt.getche() to also echo the response back to the terminal. How are you running the script? – Tommy Jul 01 '15 at 12:50

2 Answers2

2

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 !

VinceLomba
  • 398
  • 2
  • 8
  • 18
2

Im not sure this will be usefull for anyone but the answer to this is

s = input()

This will store the input in the "s" variable.

Luciano F
  • 63
  • 7