import time
import ctypes
import threading
user32 = ctypes.windll.user32
mouse_clicks = 0
keystrokes = 0
def getKeyPressed():
global mouse_clicks
global keystrokes
for i in range(0,256):
if user32.GetAsyncKeyState(i):
# if not i == 19:
# print "pressed %d and st = %d " % (i, user32.GetAsyncKeyState(i))
if i == 1:
mouse_clicks += 1
print "left"
return time.time()
elif 32 < i < 127:
keystrokes += 1
return None
def pr():
global mouse_clicks
global keystrokes
while True:
print "mouse = %d and key = %d "% (mouse_clicks, keystrokes)
time.sleep(1)
th = threading.Thread(target=pr)
th.start()
while True:
getKeyPressed()
按一次上述代码会产生多个单击结果 如何通过修改上述程序获得正确的击键和点击次数
相关问题 更多 >
编程相关推荐