简体   繁体   English

如何检查左键单击按钮是否被主动按住?

[英]How do I check that the left click button is actively being held down?

I want to move my mouse down 10 pixels every time that my left click is held in.每次按住左键时,我都想将鼠标向下移动 10 像素。

import keyboard
import mouse

keyboard.wait('-')

while mouse.click('left') == True:
    mouse.move(0, 100, absolute=False, duration=0.2)

I would recommend using libraries such as pyautogui and pynput like so:我建议使用pyautoguipynput类的库,如下所示:

from pynput.mouse import Listener
import pyautogui

x,y = pyautogui.position()

def on_click(x, y, button, pressed):
    if pressed:
        pyautogui.moveTo(x+10,y)
    
with Listener(on_click=on_click) as listener:
    listener.join()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将事件绑定到按住鼠标左键? - How do I bind an event to the left mouse button being held down? Python 检查鼠标左键是否被按住? - Python check if Left Mouse Button is being held? 在 windows 使用 python 如何检查鼠标中键是否被按住? - In windows using python how do I check if the middle mouse button is held down? 如何使用pyautogui检查特定的组合键和鼠标左键是否按下? - How to check if a specific Key combination and mouse left button is held down using pyautogui? 只要按下拍摄按钮,如何继续拍摄 - How to keep shooting as long as the shoot button is being held down 按住键时如何快速单击鼠标按钮 - How to click mouse button rapidly when key is held down 如何检测Tkinter中是否按住了某个键? - How to detect if a key is being held down in Tkinter? 如何仅在按住鼠标单击时激活循环? (松开按键时停止循环)PYTHON 3 - How to activate the loop only if mouse click is being held down? (Stop the loop when releasing the key) PYTHON 3 如果按住某个键,我将如何实施? - How would I implement if a key is held down? 如何在pygame中(左)鼠标按钮按下时检查鼠标运动(和方向)? - how to check mousemotion (and direction) while (left) mouse button is down in pygame?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM