-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_thread.py
77 lines (72 loc) · 1.95 KB
/
test_thread.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
import threading
from time import sleep
from pynput.mouse import Controller, Button, Listener
from time import sleep, time
from pynput import keyboard
from keys import Keys
speed = 0
stop=False
s_down = 0
stop_time=0
ctr = Keys()
# def speed_control():
# global speed, stop
# ctr = Keys()
# while(not stop):
# ctr.directKey('w')
# sleep(speed*0.5)
# ctr.directKey('w', ctr.key_release)
# sleep(1)
def on_press(key):
try:
global s_down
# if key.char=='s' and s_down==0:
# s_down = time()
except AttributeError:
print('special key {0} pressed'.format(
key))
def on_release(key):
try:
global speed, stop, s_down, stop_time, ctr
if key==keyboard.Key.esc:
stop=True
return False
# if key.char=='s':
# print('press time:{}'.format(time()-s_down))
# s_down=0
if key.vk==(96+8):
stop_time+=0.1
print('stop_time{}'.format(stop_time))
if key.vk==(96+2):
if stop_time>0:
stop_time-=0.1
print('stop_time{}'.format(stop_time))
if key.vk==(96+5):
ctr.directKey('s')
sleep(stop_time)
ctr.directKey('s', ctr.key_release)
if key.vk==(96+4):
for i in range(2):
ctr.directKey('6')
ctr.directKey('6', ctr.key_release)
if key.vk==(96+6):
for i in range(2):
ctr.directKey('7')
ctr.directKey('7', ctr.key_release)
except AttributeError:
print('special key {0} pressed'.format(
key))
def main():
global speed, stop
# t1 = threading.Thread(target=speed_control)
# t1.start()
lis = keyboard.Listener(
on_release=on_release,
on_press = on_press,
)
lis.start()
while(not stop):
pass
lis.stop()
if __name__ == '__main__':
main()