This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·65 lines (57 loc) · 2.29 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import keyboard
from time import sleep
import json
import tkinter
from pynput.keyboard import Key, Controller
pynput_controller = Controller()
VALID_KEYS = "qwertyuiop[]asdfghjkl;'zxcvbnm,./"
KEYS_OPTION_SELECT = "1234567890-="
with open("keys_config.json", encoding='utf-8') as config_file:
CONFIG = json.load(config_file)
key_delay = round(CONFIG["delay"] / 0.05)
keys = CONFIG["keys"]
def run_on_press(key_info: keyboard.KeyboardEvent):
if key_info.name not in VALID_KEYS:
return
for _ in range(key_delay):
sleep(0.05)
if not keyboard.is_pressed(key_info.name):
return
keyboard.release(key_info.name)
keyboard.press_and_release("backspace")
input_win = tkinter.Tk()
input_win.overrideredirect(True)
input_win.geometry("-50-50")
input_win.attributes("-topmost", True)
input_win.configure(bg='black')
items_for_this = keys[key_info.name]
for index, each_item in enumerate(items_for_this):
tkinter.Label(input_win, text=each_item, width=len(each_item), font=("Helvetica", 20), bg='black', fg='light blue').grid(row=1, column=index)
tkinter.Label(input_win, text=index+1, width=5, font=("Helvetica", 10), bg='black', fg='light grey').grid(row=2, column=index)
input_win.update()
while True:
for i in KEYS_OPTION_SELECT:
if keyboard.is_pressed(i):
try:
if i == '0':
char_select = (items_for_this[9])
elif i == '-':
char_select = (items_for_this[10])
elif i == '=':
char_select = (items_for_this[11])
else:
char_select = (items_for_this[int(i) - 1])
except IndexError:
input_win.destroy()
keyboard.press_and_release('backspace')
return
input_win.destroy()
keyboard.press_and_release('backspace')
if keyboard.is_pressed('shift'):
keyboard.write(char_select.upper())
else:
pynput_controller.type(char_select)
return
keyboard.on_press(run_on_press)
print('Running: try pressing and holding a key!')
keyboard.wait()