getch python returning without using

0

I am trying to use getch of python to get the key the user pressed, but without pressing anything it is returning " b'\xff' ", and if I use ord(getch()) , it returns 255. If I can help thank you.

from msvcrt 
import getch key = msvcrt.getch() 
print(getch()) 
if key == 0: 
    quit() 
elif key == 1: 
    print("Game inicado") 
else: 
    print('Opção invalida!') 
    
asked by anonymous 26.11.2016 / 21:18

1 answer

0

Your syntax is wrong at the beginning:

Instead of:

from msvcrt 
import getch key = msvcrt.getch() 

Should be:

from msvcrt import getch
key = msvcrt.getch() 

In addition, this piece is suspect:

print(getch())

I think what you wanted was this:

print(key)

And also, instead of key == 0 and key == 1 , you should use key == '0' and key == '1' . That is, you forgot to put the quotes.

    
26.11.2016 / 22:19