1import getkey, os
2def clear():
3 if os.name == "nt":
4 _ = os.system('cls') #Clear function
5 else:
6 _ = os.system('clear')
7current = ""
8while True:
9 clear() #Clearing, required at beginning at end in order for algorithm to work
10 print(current)
11 key = getkey.key() # Gets the key
12 if key == getkey.keys.BACKSPACE: # Detects if key is backspace
13 current = current[:-1]
14 elif key == getkey.keys.ENTER: # Detecs if key is the enter(return) key
15 break
16 else:
17 current = current + key # Otherwise, adds on the the current variable
18 clear()
19clear()
20print("\n\n\n You typed: " + current)
21
1from getkey import getkey, keys
2key = getkey()
3if key == keys.UP:
4 ... # Handle the UP key
5elif key == keys.DOWN:
6 ... # Handle the DOWN key
7elif key == 'a':
8 ... # Handle the `a` key
9elif key == 'Y':
10 ... # Handle `shift-y`
11else:
12 # Handle other text characters
13 buffer += key
14 print(buffer)
15