其他分享
首页 > 其他分享> > pynput鼠标事件

pynput鼠标事件

作者:互联网

import pynput

start = None
end = None

def on_click(x, y, button, pressed):
    global start, end
    print('{0} {1} at {2}'.format(button,'Pressed' if pressed else 'Released',(x, y)))
    if str(button) == "Button.left" and pressed:  # if mouse left button down
        start = (x,y)
    if not pressed and str(button) == "Button.left":  # if mouse left button up
        end = (x,y)
    if not pressed:
        # Stop listener
        return False

# Collect events until released
with pynput.mouse.Listener(on_click=on_click) as listener:
    listener.join()
print(f"Start coordinate:{start}, end coordinate:{end}")

标签:end,鼠标,button,start,pressed,pynput,left,mouse,事件
来源: https://www.cnblogs.com/wztshine/p/15043652.html