from pynput.mouse import Listener, Button
import time
# 存储按下时间
press_time = 0
def on_click(x, y, button, pressed):
global press_time
if button == Button.left:
if pressed:
# 记录按下时间
press_time = time.time()
else:
# 计算持续时间并打印
duration = time.time() - press_time
print(f"Mouse left button was held for {duration:.4f} seconds")
# 设置监听器
with Listener(on_click=on_click) as listener:
listener.join()
最后修改:2024 年 06 月 20 日
© 允许规范转载
1 条评论
陈蓠吁:文章真不错http://wap.jst-gpmx.cn/news/4996.html