Created
January 22, 2022 01:46
-
-
Save NaClYen/b644916a2e34b1bae28ba31e19ffc93e to your computer and use it in GitHub Desktop.
py auto mouse click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# press Esc to exit app | |
# click mouse mid button to switch working | |
from operator import eq | |
import time | |
from pynput.mouse import Button, Controller | |
from pynput import mouse | |
from pynput import keyboard | |
mouseCtrl = Controller() | |
ctrl = { | |
"working": False, | |
"exit": False | |
} | |
def on_click(x, y, button, pressed): | |
if button == Button.middle and pressed: | |
ctrl["working"] = not ctrl["working"] | |
tmp = ctrl["working"] | |
print(f"current working flag is {tmp}") | |
pass | |
# print(f"mouse click at ({x}, {y}) with {button}, pressed ? {pressed}") | |
pass | |
muListener = mouse.Listener( | |
on_click=on_click) | |
muListener.start() | |
# with mouse.Listener( | |
# on_click=on_click) as listener: | |
# listener.join() | |
def on_release(key): | |
print('{0} released'.format( | |
key)) | |
if key == keyboard.Key.esc: | |
ctrl["exit"] = True | |
# Stop listener | |
return False | |
# with keyboard.Listener(on_release=on_release) as kbListener: | |
# kbListener.join() | |
kbListener = keyboard.Listener(on_release=on_release) | |
kbListener.start() | |
while True: | |
# print(f"looping: {ctrl}") | |
if ctrl["exit"]: | |
break | |
if ctrl["working"]: | |
mouseCtrl.click(Button.left) | |
# print(f"click!") | |
pass | |
time.sleep(1) | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment