You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently this script moves the mouse to the top left corner of my screen.
I am trying to write a script that continuously sends left mouse clicks at the current mouse cursor position while the left mouse button is held down and stops clicking on release of the left mouse button.
from pynput.mouse import Listener as MouseListener
from pynput.keyboard import Listener as KeyboardListener
def on_press(key):
print("Key pressed: {0}".format(key))
def on_release(key):
print("Key released: {0}".format(key))
def on_move(x, y):
print("Mouse moved to ({0}, {1})".format(x, y))
from pymouse import PyMouse
import time
sleep_time = 2
def on_click(x, y, button, pressed):
if pressed:
m = PyMouse()
print('Mouse clicked at ({0}, {0}) with {2}'.format(x, y, button))
m.click(0, 0, 1)
time.sleep(sleep_time)
m.click(0, 0, 1)
print('Mouse clicked at ({0}, {0}) with {2}'.format(x, y, button))
else:
print('Mouse released at ({0}, {0}) with {2}'.format(x, y, button))
def on_scroll(x, y, dx, dy):
print('Mouse scrolled at ({0}, {1})({2}, {3})'.format(x, y, dx, dy))
# Setup the listener threads
keyboard_listener = KeyboardListener(on_press=on_press, on_release=on_release)
mouse_listener = MouseListener(on_move=on_move, on_click=on_click, on_scroll=on_scroll)
# Start the threads and join them so the script doesn't end early
keyboard_listener.start()
mouse_listener.start()
keyboard_listener.join()
mouse_listener.join()
I also plan to try while pressed: instead of if pressed:
The text was updated successfully, but these errors were encountered:
NSC9
changed the title
How do I specify that I want to click where the mouse pointer is, and no move the mouse anwhere?
How do I specify that I want to click where the mouse pointer is, and not move the mouse anwhere?
Feb 26, 2022
Currently this script moves the mouse to the top left corner of my screen.
I am trying to write a script that continuously sends left mouse clicks at the current mouse cursor position while the left mouse button is held down and stops clicking on release of the left mouse button.
I also plan to try
while pressed:
instead ofif pressed:
The text was updated successfully, but these errors were encountered: