-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkey.py
More file actions
70 lines (54 loc) · 1.38 KB
/
key.py
File metadata and controls
70 lines (54 loc) · 1.38 KB
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
from pynput import keyboard, mouse
from logger import log
from threading import Thread
def on_press(key):
try:
log(key.vk)
except AttributeError:
if key.name != 'space':
log(int(str(key.value)[1:-1]))
else:
log(32)
except:
pass
def on_release(key):
try:
log(-key.vk)
except AttributeError:
if key.name != 'space':
log(-int(str(key.value)[1:-1]) - 3)
else:
log(-32 - 3)
except:
pass
def on_click(x, y, button, pressed):
try:
log(-1, (int(button.name == 'left') * 2 - 1) * x, (int(pressed) * 2 - 1) * y)
except:
pass
def on_scroll(x, y, dx, dy):
try:
log(-2, x, y, dx, dy)
except:
pass
class KeyThread(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
with keyboard.Listener(
on_press=on_press,
on_release=on_release) as keylistener:
keylistener.join()
class MouseThread(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
with mouse.Listener(
on_click=on_click,
on_scroll=on_scroll) as mouselistener:
mouselistener.join()
if __name__ == '__main__':
kthread = KeyThread()
kthread.start()
mthread = MouseThread()
mthread.start()