add ctrl key, heck that was annoying to figure out
This commit is contained in:
Binary file not shown.
47
input.py
47
input.py
@ -1,47 +1,86 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from kb import write_str
|
from kb import write_str
|
||||||
from kb import write_special
|
from kb import write_special
|
||||||
|
from kb import write_ctrl
|
||||||
|
from kb import clear
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from getch import _Getch
|
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();
|
get = _Getch();
|
||||||
while True:
|
while True:
|
||||||
input_key = get()
|
input_key = get()
|
||||||
print(input_key + ": " + str(ord(input_key)))
|
print(input_key + ": " + str(ord(input_key)))
|
||||||
#if input_key == "?":
|
#if input_key == "?":
|
||||||
# break
|
# 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:
|
if ord(input_key) == 127:
|
||||||
write_special("BACKSPACE_DELETE")
|
write_special("BACKSPACE_DELETE")
|
||||||
|
clear()
|
||||||
continue
|
continue
|
||||||
if ord(input_key) == 9:
|
if ord(input_key) == 9:
|
||||||
write_special("TAB")
|
write_special("TAB")
|
||||||
|
clear()
|
||||||
continue
|
continue
|
||||||
if ord(input_key) == 27:
|
if ord(input_key) == 27:
|
||||||
print("Special key detected!")
|
print("Special key detected!")
|
||||||
key = [x for x in "ABCDE7890134~2"]
|
#key = [x for x in "ABCDE7890134~2"]
|
||||||
input_key = get()
|
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:
|
if ord(input_key) == 27:
|
||||||
break
|
break
|
||||||
if input_key == "[":
|
if input_key == "[":
|
||||||
again = False
|
again = False
|
||||||
input_key = get()
|
input_key = get()
|
||||||
|
print(input_key)
|
||||||
if 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()
|
input_key = get()
|
||||||
# print(input_key)
|
print(input_key)
|
||||||
num = key.index(input_key) + 1
|
num = key.index(input_key) + 1
|
||||||
if num == 13: # del
|
if num == 13: # del
|
||||||
print("pressing DEL")
|
print("pressing DEL")
|
||||||
write_special("DELETE")
|
write_special("DELETE")
|
||||||
|
clear()
|
||||||
continue
|
continue
|
||||||
if num == 14:
|
if num == 14:
|
||||||
print("pressing prtscr / sysrq")
|
print("pressing prtscr / sysrq")
|
||||||
write_special("PRINT_SCREEN")
|
write_special("PRINT_SCREEN")
|
||||||
|
clear()
|
||||||
get()
|
get()
|
||||||
continue
|
continue
|
||||||
print("pressing F" + str(num))
|
print("pressing F" + str(num))
|
||||||
write_special("F" + str(num))
|
write_special("F" + str(num))
|
||||||
|
clear()
|
||||||
if again:
|
if again:
|
||||||
get()
|
get()
|
||||||
#if int(input_key) > 0 and int(input_key) <= 9:
|
#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)
|
#write_report(NULL_CHAR*8)
|
||||||
# Press SHIFT + a = A
|
# Press SHIFT + a = A
|
||||||
#write_report(chr(32)+NULL_CHAR+chr(4)+NULL_CHAR*5)
|
#write_report(chr(32)+NULL_CHAR+chr(4)+NULL_CHAR*5)
|
||||||
|
#print(chr())
|
||||||
# Press b
|
# Press b
|
||||||
#write_report(NULL_CHAR*2+chr(5)+NULL_CHAR*5)
|
#write_report(NULL_CHAR*2+chr(5)+NULL_CHAR*5)
|
||||||
# Release keys
|
# Release keys
|
||||||
@ -40,16 +40,18 @@ def write_report(report):
|
|||||||
|
|
||||||
# Release all keys
|
# Release all keys
|
||||||
#write_report(NULL_CHAR*8)
|
#write_report(NULL_CHAR*8)
|
||||||
|
key = ")!@#$%^&*("
|
||||||
|
|
||||||
|
|
||||||
def write_char(char):
|
def write_char(char):
|
||||||
write_report(NULL_CHAR*2+chr(char)+NULL_CHAR*5)
|
write_report(NULL_CHAR*2+chr(char)+NULL_CHAR*5)
|
||||||
def write_caps(char):
|
def write_caps(char):
|
||||||
write_report(chr(32)+NULL_CHAR+chr(char)+NULL_CHAR*5)
|
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):
|
def write_str(word):
|
||||||
for letter in 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 == ")":
|
if letter in ")!@#$%^&*(":
|
||||||
key = [x for x in ")!@#$%^&*("]
|
|
||||||
num = key.index(letter)
|
num = key.index(letter)
|
||||||
write_caps(keycodes.keycodelst[str(num)])
|
write_caps(keycodes.keycodelst[str(num)])
|
||||||
write_report(NULL_CHAR*8)
|
write_report(NULL_CHAR*8)
|
||||||
@ -97,9 +99,9 @@ def write_special(input):
|
|||||||
write_char(keycodes.keycodelst[input])
|
write_char(keycodes.keycodelst[input])
|
||||||
except:
|
except:
|
||||||
print("Unknown HID keycode")
|
print("Unknown HID keycode")
|
||||||
finally:
|
|
||||||
write_report(NULL_CHAR*8)
|
|
||||||
|
|
||||||
|
def clear():
|
||||||
|
write_report(NULL_CHAR*8)
|
||||||
#write_str("root\n")
|
#write_str("root\n")
|
||||||
#time.sleep(0.5)
|
#time.sleep(0.5)
|
||||||
#write_str("qwertypass\n")
|
#write_str("qwertypass\n")
|
||||||
|
Reference in New Issue
Block a user