I want to output something when the user enters a specific key
from msvcrt import getch
def select():
#do something
def moveDown():
#do something
def moveUp():
#do something
def main3():
while True:
key = ord(getch())
if key == 27: #escape
break
elif key == 13: #enter
select()
elif key == 224: #Special keys (arrows, F keys, ins, del, etc.)
key = ord(getch())
if key == 80: #Up arrow
moveDown()
elif key == 72: #Down arrow
moveUp()
http://www.theasciicode.com.ar/ascii-control-characters/escape-ascii-code-27.html
--Responds only on the command prompt (I wanted the input on any window to respond) --Window OS only
http://stackoverflow.com/questions/12175964/python-method-for-reading-keypress
Recommended Posts