[英]How to make the Keyboard module detect if a right click was made
I have tried to search google and other websites such as GitHub but I cant find a way to detect if the right key has been pressed.我曾尝试搜索 google 和其他网站,例如 GitHub,但我找不到检测是否按下了右键的方法。 I am using the two modules Keyboard and Pyautogui to make a auto clicker but all the ideas that I have come up with have failed.
我正在使用 Keyboard 和 Pyautogui 这两个模块来制作自动点击器,但我提出的所有想法都失败了。 Here is my code:
这是我的代码:
import keyboard
import pyautogui
pyautogui.PAUSE = 0.1
while True:
if keyboard.is_pressed('h'):
pyautogui.rightClick()
if keyboard.is_pressed('g'):
pyautogui.click()
I want a way to replace the h and g with right click and left click any ideas?我想要一种用右键单击和左键单击替换h和g的方法有什么想法吗?
If you are trying to check for just mouse clicks, the pynput library could work.如果您只是尝试检查鼠标点击,那么 pynput 库可以工作。
from pynput import mouse
# mouse.Events looks at all events, you could use
# events = mouse.Events().get(1) to look at just the events in the last second
with mouse.Events() as events:
for event in events:
if isinstance(event, mouse.Events.Click):
if event.button == mouse.Button.right and event.pressed:
#Do stuff for right click
else:
print('Received event {}'.format(event))
I am using Click so that movements are not tracked.我正在使用 Click,以便不跟踪移动。 Similarly, press down/up are counted as separate events, so to filter those out using event.pressed
同样,按下/向上被计为单独的事件,因此使用 event.pressed 过滤掉这些事件
Take a look at https://pynput.readthedocs.io/en/latest/mouse.html for other mouse listener ideas查看https://pynput.readthedocs.io/en/latest/mouse.html了解其他鼠标监听器的想法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.