Python全局捕获和处置鼠标点击事件
我想创建一个工具,该工具使我可以使用鼠标将密钥发送到活动窗口。
假设我单击左鼠标按钮时,我想发送键“ a”。但是我也想抑制 /处理该特定的点击事件。因此,目标应用只会感觉到键盘输入“ A”,而不会感觉到鼠标事件的左键单击。
使用以下代码,我可以看到鼠标点击。但是我想处置 /停止活动,而不是系统处理。
from pynput import mouse
def do_something():
print("something")
def on_click(x, y, button, pressed):
print('{0} {1} at {2}'.format(button, 'Pressed' if pressed else 'Released', (x, y)))
if (button.value == 1):
do_something()
#suppress / dispose the click event...
# Collect events until released
with mouse.Listener( on_click=on_click ) as listener:
listener.join()
顺便说一句,我正在使用Ubuntu 20.04。 提前致谢。
I want to create a tool, which allows me to send keys to active window using my mouse.
Let's say I want to send the key "A" when I click the left mouse button. But I also want to suppress / dispose that particular click event. So the target app will only feel the keyboard input "A", but not the left click of the mouse event.
With the following code I am able to see the mouse clicks. But I want to dispose / stop the event and not processed by the system.
from pynput import mouse
def do_something():
print("something")
def on_click(x, y, button, pressed):
print('{0} {1} at {2}'.format(button, 'Pressed' if pressed else 'Released', (x, y)))
if (button.value == 1):
do_something()
#suppress / dispose the click event...
# Collect events until released
with mouse.Listener( on_click=on_click ) as listener:
listener.join()
By the way I am using Ubuntu 20.04.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一种抑制所有点击事件的方法。
我仍在寻找一种解决方案来抑制某个按钮的点击。
I found a way that suppress all the click events.
I am still looking for a solution to suppress a certain button click.