python上的user32.GetAsyncKeyState捕获键和鼠标单击

问题描述

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()

上面的代码一次按一次会产生多次点击结果 如何通过修改上述程序来获得正确的击键次数和点击次数?

解决方法

var nonDuplicatedPoints = from p in points1
                          group p by p into g 
                          where g.Count() == 1
                          select g.Key;

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...