getkey module python code example
Example 1: python get key module
import getkey, os
def clear():
if os.name == "nt":
_ = os.system('cls')
else:
_ = os.system('clear')
current = ""
while True:
clear()
print(current)
key = getkey.key()
if key == getkey.keys.BACKSPACE:
current = current[:-1]
elif key == getkey.keys.ENTER:
break
else:
current = current + key
clear()
clear()
print("\n\n\n You typed: " + current)
Example 2: getkey python module
from getkey import getkey, keys
key = getkey()
if key == keys.UP:
...
elif key == keys.DOWN:
...
elif key == 'a':
...
elif key == 'Y':
...
else:
buffer += key
print(buffer)