add ctrl key, heck that was annoying to figure out
This commit is contained in:
parent
4dd36b5e34
commit
abf14d4f97
Binary file not shown.
47
input.py
47
input.py
@ -1,47 +1,86 @@
|
||||
#!/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) > 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) == 13:
|
||||
write_special("ENTER")
|
||||
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!")
|
||||
key = [x for x in "ABCDE7890134~2"]
|
||||
#key = [x for x in "ABCDE7890134~2"]
|
||||
input_key = get()
|
||||
#print(ord(input_key))
|
||||
print(input_key)
|
||||
#if ord(input_key) == 91:
|
||||
# input_key = get()
|
||||
# #arrowkey = [x for x in "ABCD"]
|
||||
# #arrowout = ["UP_ARROW", "DOWN_ARROW", "RIGHT_ARROW", "LEFT_ARROW"]
|
||||
# write_special(arrowout[arrowkey.index(input_key)])
|
||||
# print("pressing " + arrowout[arrowkey.index(input_key)])
|
||||
# continue
|
||||
if ord(input_key) == 27:
|
||||
break
|
||||
if input_key == "[":
|
||||
again = False
|
||||
input_key = get()
|
||||
print(input_key)
|
||||
if input_key != "[":
|
||||
again = True
|
||||
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)
|
||||
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()
|
||||
#if int(input_key) > 0 and int(input_key) <= 9:
|
||||
|
12
kb.py
12
kb.py
@ -14,7 +14,7 @@ def write_report(report):
|
||||
#write_report(NULL_CHAR*8)
|
||||
# Press SHIFT + a = A
|
||||
#write_report(chr(32)+NULL_CHAR+chr(4)+NULL_CHAR*5)
|
||||
|
||||
#print(chr())
|
||||
# Press b
|
||||
#write_report(NULL_CHAR*2+chr(5)+NULL_CHAR*5)
|
||||
# Release keys
|
||||
@ -40,16 +40,18 @@ def write_report(report):
|
||||
|
||||
# Release all keys
|
||||
#write_report(NULL_CHAR*8)
|
||||
key = ")!@#$%^&*("
|
||||
|
||||
|
||||
def write_char(char):
|
||||
write_report(NULL_CHAR*2+chr(char)+NULL_CHAR*5)
|
||||
def write_caps(char):
|
||||
write_report(chr(32)+NULL_CHAR+chr(char)+NULL_CHAR*5)
|
||||
def write_ctrl(char):
|
||||
write_report(chr(1)+NULL_CHAR+chr(keycodes.keycodelst[char])+NULL_CHAR*5)
|
||||
def write_str(word):
|
||||
for letter in word:
|
||||
if letter == "!" or letter == "@" or letter == "#" or letter == "$" or letter == "%" or letter == "^" or letter == "&" or letter == "*" or letter == "(" or letter == ")":
|
||||
key = [x for x in ")!@#$%^&*("]
|
||||
if letter in ")!@#$%^&*(":
|
||||
num = key.index(letter)
|
||||
write_caps(keycodes.keycodelst[str(num)])
|
||||
write_report(NULL_CHAR*8)
|
||||
@ -97,9 +99,9 @@ def write_special(input):
|
||||
write_char(keycodes.keycodelst[input])
|
||||
except:
|
||||
print("Unknown HID keycode")
|
||||
finally:
|
||||
write_report(NULL_CHAR*8)
|
||||
|
||||
def clear():
|
||||
write_report(NULL_CHAR*8)
|
||||
#write_str("root\n")
|
||||
#time.sleep(0.5)
|
||||
#write_str("qwertypass\n")
|
||||
|
Loading…
x
Reference in New Issue
Block a user