Reputation: 21
while True:
key = ord(getch())
if key == 72:
print "up"
time.sleep(1)
elif key == 80:
print "down."
time.sleep(1)
I am searching for same kind of codes for arrow keys.
What are the codes for LEFT and RIGHT?
Upvotes: 2
Views: 3040
Reputation: 5919
It seems like you are calling the _getch function which is provided in the msvcrt
module on Windows platforms.
Note that the arrow keys are delivered as two values, that is, your values for UP and DOWN are wrong (alone, 72 is 'H' and 80 is 'P').
By complementing the documentation above with experimentation it seems like the answer may be:
First call _getch
once, and if it's either 0 or 224, call it again to get the actual key codes for the arrow keys.
Upvotes: 2
Reputation: 16029
while True:
key = ord(getch())
print(key)
and then press the keys you want to know.
Upvotes: 1