forked from taojy123/KeymouseGo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeymouseGo.py
80 lines (56 loc) · 1.51 KB
/
KeymouseGo.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
#!/usr/bin/env python
#Boa:App:BoaApp
import time
import os
import sys
import json
import threading
import wx
import pyWinhook
import pythoncom
import Frame1
modules = {'Frame1': [1, 'Main frame of Application', u'Frame1.py']}
class BoaApp(wx.App):
def OnInit(self):
self.main = Frame1.create(None)
self.main.Show()
self.SetTopWindow(self.main)
return True
def main():
application = BoaApp(0)
application.MainLoop()
def single_run(script_path, run_times=1):
t = HookThread()
t.start()
try:
j = 0
while j < run_times or run_times == 0:
j += 1
print('===========', j, '==============')
Frame1.RunScriptClass.run_script_once(script_path)
print('script run finish!')
except Exception as e:
raise e
finally:
os._exit(0)
class HookThread(threading.Thread):
def run(self):
def on_keyboard_event(event):
key_name = event.Key.lower()
stop_name = 'f9'
if key_name == stop_name:
print('break exit!')
os._exit(0)
return True
hm = pyWinhook.HookManager()
hm.KeyAll = on_keyboard_event
hm.HookKeyboard()
pythoncom.PumpMessages()
if __name__ == '__main__':
print(sys.argv)
if len(sys.argv) > 1:
script_path = sys.argv[1]
run_times = int(sys.argv[2]) if len(sys.argv) > 2 else 1
single_run(script_path, run_times)
else:
main()