-
Notifications
You must be signed in to change notification settings - Fork 4
/
autogui.py
71 lines (60 loc) · 1.88 KB
/
autogui.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
import sys
import pyWinhook
import pythoncom
import win32api
import run
import wincore
mainHander = ""
class autogui():
def __init__(self):
self.runnerThread=""
self.nowMousePosition=""
self.hm = pyWinhook.HookManager()
self.hm.KeyAll = self.onKeyboardEvent
self.hm.HookKeyboard()
# 监听鼠标
# hm.MouseAll = self.onMouseEvent
# hm.HookMouse()
# pythoncom.PumpMessages()
def onKeyboardEvent(self,event):
print(event.Key) # 返回按下的键
if(event.Key == "F9"):
print("start!")
mainHander.runnerThread.go()
elif(event.Key == "F10"):
print("stop!")
mainHander.runnerThread.close()
mainHander.listenStop()
elif(event.Key == "F8"):
print(mainHander.nowMousePosition)
return True
def runnerInit(self,scriptPath,count):
self.runnerThread = run.Runner()
self.runnerThread.start()
self.runnerThread.setScritpsPath(scriptPath)
self.runnerThread.setCount(int(count))
def listenStart(self):
pythoncom.PumpMessages()
def listenStop(self):
win32api.PostQuitMessage()
# 监听到鼠标事件调用
def onMouseEvent(self,event):
#if(event.MessageName=="mouse move"):
#print(event.MessageName)
# mainHander.nowMousePosition = event.Position
# print(event.Position)
return True
if __name__=='__main__':
print(sys.argv)
#命令方式执行脚本
if len(sys.argv) == 3:
scriptPath = sys.argv[1]
count = sys.argv[2]
mainHander = autogui()
mainHander.runnerInit(scriptPath,count)
mainHander.listenStart()
#启动窗体
elif(len(sys.argv) == 1):
wincore.windowsOpen(sys)
else:
print("input error "+ str(len(sys.argv)))