-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
98 lines (80 loc) · 2.73 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
import sys
import tkinter as tk
import keyboard
import mouse
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except AttributeError:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
def s(key):
global stat
if not stat[key]:
for key_iter in range(len(stat)):
if stat[key_iter] and key_iter != key:
match key_iter:
case 0:
mouse.release(button="left")
case 1:
mouse.release(button="middle")
case 2:
mouse.release(button="right")
stat[key_iter] = False
stat[key] = True
match key:
case 0:
mouse.press(button="left")
case 1:
mouse.press(button="middle")
case 2:
mouse.press(button="right")
def r(key):
global stat
match key:
case 0:
mouse.release(button="left")
case 1:
mouse.release(button="middle")
case 2:
mouse.release(button="right")
stat[key] = False
def main():
global stat
stat = [False, False, False] # left - 0 | middle - 1 | right - 0
root = tk.Tk()
root.resizable(False, False)
root.geometry(f"250x125+{root.winfo_screenwidth() // 2 - 125}+{root.winfo_screenheight() // 2 - 62}")
root.title("Key-Click")
root.iconbitmap(resource_path("resources/key-click-icon.ico"))
root.config(background="#ffffff")
title = tk.Label(root, background="#ffffff", activebackground="#ffffff", foreground="#000000", activeforeground="#000000", text="Key-Click", font=("Helvetica", 23, "italic", "bold"))
title.place(x=0, y=0, width=250, height=65)
instructions = tk.Label(root, background="#ffffff", activebackground="#ffffff",
foreground="#000000", activeforeground="#000000",
text="left arrow key = left mouse button\n"
"right arrow key = right mouse button\n"
"down arrow key = middle mouse button",
font=("Helvetica", 9, "italic", "bold"))
instructions.place(x=0, y=60, width=250, height=65)
keyboard.on_press_key("Left", lambda event: s(0), suppress=True)
keyboard.on_release_key("Left", lambda event: r(0), suppress=True)
keyboard.on_press_key("Down", lambda event: s(1), suppress=True)
keyboard.on_release_key("Down", lambda event: r(1), suppress=True)
keyboard.on_press_key("Right", lambda event: s(2), suppress=True)
keyboard.on_release_key("Right", lambda event: r(2), suppress=True)
root.mainloop()
for key in range(len(stat)):
if stat[key]:
match key:
case 0:
mouse.release(button="left")
case 1:
mouse.release(button="middle")
case 2:
mouse.release(button="right")
if __name__ == "__main__":
main()