How to use the pynput.mouse.Controller function in pynput

To help you get started, we’ve selected a few pynput examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nschapeler / GDBot / DirectInputWindows.py View on Github external
#Simulates keypresses on Mac
from pynput.mouse import Button, Controller

mouse = Controller()

#Bounce the cube by clicking on the screen
def bounce():
    mouse.position = (180, 350)
    mouse.click(Button.left, 1)

#Restart the level by clicking on the restart button
def restart():
    mouse.position = (180, 425)
    mouse.click(Button.left, 1)
github silx-kit / silx / ci / close_popup.py View on Github external
:param qt.QApplication qapp: Qt application
    :param list popupList: List of popup definitions
    """
    popup_found_count = 0
    for _ in range(10):
        image = getScreenShot(qapp)

        popup_found = False
        for popup in popupList:
            if sys.platform != popup.platform:
                logger.debug("Popup %s skipped, wrong platform.", popup.name)
                continue

            if popup.check(image):
                logger.info("Popup '%s' found. Try to close it.", popup.name)
                mouse = pynput.mouse.Controller()
                mouse.position = popup.clickPosition()
                mouse.click(pynput.mouse.Button.left)
                time.sleep(5)
                popup_found = True
                popup_found_count += 1

        if not popup_found:
            break

    if popup_found_count == 0:
        logger.info("No popup found.")
    else:
        logger.info("No more popup found.")
github nimaid / LPHK / ms.py View on Github external
from pynput.mouse import Controller, Button
from bresenham import bresenham

controller = Controller()
buttons = ["left", "middle", "right"]


def get_pos():
    return controller.position


def set_pos(x, y):
    global controller
    controller.position = (x, y)


def move_to_pos(x, y):
    controller.move(x, y)
github HBRYU / Picaso_bot / Picaso.py View on Github external
# - Do not touch or move the mouse while running, unless you want to shut it down.
# - ALL PIXEL COORDINATE VALUES ARE SET FOR 1920 * 1080 DISPLAY. If your moniter has a different
# 	aspect ratio, please set the coordinates to your value
# - Install OpenCV and pynput (pip install {opencv-python/pynput})

# I don't have much time to improve algorithm, such as only painting on the required pixels
# instead of scanning through the whole canvas like a printer. I'll be on it.

# Also, there is no fail safe... so if it goes wrong you just have to repeatedly spam alt+F4
# on the command prompt and prey that it to somehow shuts down. If you can *reach it.*

from pynput.keyboard import Key, Controller as KeyboardController
from pynput.mouse import Button, Controller as MouseController

keyboard = KeyboardController()
mouse = MouseController()
import cv2
import numpy as np
import os
import time

mouse = MouseController()
keyboard = KeyboardController()

img = cv2.imread("Mario.png") #Your image file in the same directory of this script
grayThresh = 0							#Gray brightness value AKA current max rgb value
threshStep = 30						#Gray brightness value increase amount

os.system("Start mspaint")				#Start ms paint using cmd commands

time.sleep(1)							#Wait for ms paint to actually start before spamming left click
github mozilla / iris_firefox / iris / api / core / mouse.py View on Github external
:return: None.
    """

    if duration is None:
        duration = Settings.move_mouse_delay

    if location is None:
        location = Location(0, 0)

    pyautogui.moveTo(location.x, location.y, duration)
    if parse_args().highlight:
        hl = ScreenHighlight()
        hl.draw_circle(HighlightCircle(location.x, location.y, 15))
        hl.render()
    if clicks > 1:
        mouse = Controller()
        mouse.position = (location.x, location.y)
        mouse.click(Button.left, 2)
    else:
        pyautogui.click(clicks=clicks, interval=Settings.click_delay, button=button)

    if Settings.click_delay != DEFAULT_CLICK_DELAY:
        Settings.click_delay = DEFAULT_CLICK_DELAY
github ipaleka / arrangeit / arrangeit / base.py View on Github external
def __init__(self):
        """Instatiates and sets queue."""
        self.queue = queue.Queue()
        self.control = pynput.mouse.Controller()
github lanshiqin / JerryMouse / keyboard_mouse.py View on Github external
def run(self):
        while self.execute_count > 0:
            with open(self.file_name, 'r', encoding='utf-8') as file:
                mouse_exec = MouseController()
                line = file.readline()
                while line:
                    obj = json.loads(line)
                    if obj['name'] == 'mouse':
                        if obj['event'] == 'move':
                            mouse_exec.position = (obj['location']['x'], obj['location']['y'])
                            time.sleep(0.01)
                        elif obj['event'] == 'click':
                            if obj['action']:
                                if obj['target'] == 'left':
                                    mouse_exec.press(Button.left)
                                else:
                                    mouse_exec.press(Button.right)
                            else:
                                if obj['target'] == 'left':
                                    mouse_exec.release(Button.left)
github LinusCDE / rmWacomToMouse / pcWacomToMouse.py View on Github external
#!/usr/bin/env python3
'''
Meant to run on your PC.
Receives data generated by rmServerWacomInput.py,
moves the mouse and presses accordingly.
Configure area below!
'''


import socket
import struct
from pynput.mouse import Button, Controller

mouse = Controller()

def mouseMoveAbs(x, y):
	'''The 'mouse.move()' method only moves relative.
	   This funtion works with absolute values.'''
	pos = mouse.position
	mouse.move(x - pos[0], y - pos[1])

# ----------
# Config:

ONLY_DEBUG=False  # Only show data. Don't move mouse

# Area on your display (remember to keep correct ratio (1872:1404 or 312:234) or your input will get streched/squashed!)
SCREEN_DRAW_AREA_FROM_X = 660
SCREEN_DRAW_AREA_FROM_Y = 107
SCREEN_DRAW_AREA_TO_X = 1347  # Ratio will match roughly but not exact!
github tadejmagajna / TensorMouse / tensormouse / workers.py View on Github external
def mouse_move_worker(objectX, objectY, mouse_state):
    """ Separate process worker to move mouse and perform clicks"""

    import tkinter
    from pynput.mouse import Button, Controller
    import time

    mouse = Controller()
    x,y = tkinter.Tk().winfo_screenwidth(), tkinter.Tk().winfo_screenheight()

    while True:
        if mouse_state.value == MOUSE_CLICK:
            time.sleep(0.2)
            mouse.press(Button.left)
            mouse_state.value = MOUSE_RELEASE
        if mouse_state.value == MOUSE_DRAG:
            time.sleep(0.2)
            mouse.press(Button.left)
            mouse_state.value = MOUSE_DRAGGING
        if (mouse_state.value == MOUSE_RELEASE):
            mouse.release(Button.left)
            mouse_state.value = MOUSE_NULL

        if (objectX.value > 0 and objectY.value > 0):