You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.7 KiB
Python
79 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
from kb import write_str
|
|
from kb import write_special
|
|
from kb import write_ctrl
|
|
from kb import clear
|
|
from time import sleep
|
|
from getch import _Getch
|
|
|
|
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
arrowkey = [x for x in "ABCD"]
|
|
arrowout = ["UP_ARROW", "DOWN_ARROW", "RIGHT_ARROW", "LEFT_ARROW"]
|
|
key = [x for x in "ABCDE7890134~2"]
|
|
|
|
|
|
get = _Getch();
|
|
while True:
|
|
input_key = get()
|
|
print(input_key + ": " + str(ord(input_key)))
|
|
#if input_key == "?":
|
|
# break
|
|
if ord(input_key) == 13:
|
|
write_special("ENTER")
|
|
clear()
|
|
continue
|
|
if ord(input_key) > 0 and ord(input_key) <= 26: # ctrl + alpha
|
|
idx = ord(input_key) - 1
|
|
letter = alpha[idx]
|
|
#write_special("LEFT_CTRL")
|
|
print("pressing CTRL + " + letter)
|
|
write_ctrl(letter)
|
|
clear()
|
|
continue
|
|
if ord(input_key) == 127:
|
|
write_special("BACKSPACE_DELETE")
|
|
clear()
|
|
continue
|
|
if ord(input_key) == 9:
|
|
write_special("TAB")
|
|
clear()
|
|
continue
|
|
if ord(input_key) == 27:
|
|
print("Special key detected!")
|
|
input_key = get()
|
|
#print(input_key)
|
|
if ord(input_key) == 27:
|
|
break
|
|
if input_key == "[":
|
|
again = False
|
|
input_key = get()
|
|
#print(input_key)
|
|
if input_key != "[":
|
|
if input_key in arrowkey:
|
|
write_special(arrowout[arrowkey.index(input_key)])
|
|
clear()
|
|
print("pressing " + arrowout[arrowkey.index(input_key)])
|
|
continue
|
|
else:
|
|
again = True
|
|
input_key = get()
|
|
#print(input_key)
|
|
num = key.index(input_key) + 1
|
|
if num == 13: # del
|
|
print("pressing DEL")
|
|
write_special("DELETE")
|
|
clear()
|
|
continue
|
|
if num == 14:
|
|
print("pressing prtscr / sysrq")
|
|
write_special("PRINT_SCREEN")
|
|
clear()
|
|
get()
|
|
continue
|
|
print("pressing F" + str(num))
|
|
write_special("F" + str(num))
|
|
clear()
|
|
if again:
|
|
get()
|
|
write_str(input_key)
|