Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I specify that I want to click where the mouse pointer is, and not move the mouse anwhere? #127

Open
NSC9 opened this issue Feb 26, 2022 · 0 comments

Comments

@NSC9
Copy link

NSC9 commented 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.

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:

@NSC9 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant