How to use the pynput.mouse 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 moses-palmer / pynput / tests / mouse_listener_tests.py View on Github external
import pynput.mouse
import time

from . import EventTest, darwin, win32, xorg


class MouseListenerTest(EventTest):
    NOTIFICATION = (
        'This test case is interactive, so you must follow the instructions '
        'on screen.\n'
        'You do not have to perform any actions on this specific window.')
    LISTENER_CLASS = pynput.mouse.Listener

    def test_cursor(self):
        """Asserts that all cursor types defined for the base interface are
        defined for the current platform"""
        from pynput.mouse._base import Cursor
        for cursor in Cursor:
            self.assertTrue(
                hasattr(pynput.mouse.Cursor, cursor.name),
                '%s is not defined for the current platform' % cursor.name)

    def test_stop(self):
        """Tests that stopping the listener from a different thread works"""
        listener = self.listener()

        listener.start()
        listener.wait()
github deverlabs / grappe / worker / worker.py View on Github external
return self.run(True)


if __name__ == "__main__":
    try:
        print("Grappe Worker successfully started")
        Grappe = Manager()
        Grappe.start()
        Socket = SocketServer("localhost", 1234)
        Socket.start()
        ctrlListener = Listener(writeToClient)
        ctrlListener.start()
        listener = keyboard.Listener(
            on_press=ctrlListener.handle_key_press)
        listener.start()
        mouseListener = mouse.Listener(
            on_click=ctrlListener.handle_mouse_click)
        mouseListener.start()

    except KeyboardInterrupt:
        print('Interrupted')
        try:
            sys.exit(0)
        except SystemExit:
            os._exit(0)
github deverlabs / grappe / worker-v2 / worker.py View on Github external
PING_SENDED = True
                writeToClient(json.dumps({"event": "ping", "message" : 0}))
            return self.run(True)


if __name__ == "__main__":
    try:
        print("Grappe Worker successfully started")
        Grappe = Manager()
        Grappe.start()
        Socket = SocketServer("localhost", 1234)
        Socket.start()
        listener = keyboard.Listener(
            on_press=on_press)
        listener.start()
        mouseListener = mouse.Listener(
            on_click=on_click)
        mouseListener.start()

    except KeyboardInterrupt:
        print('Interrupted')
        try:
            sys.exit(0)
        except SystemExit:
            os._exit(0)
github CopyTranslator / CopyTranslator / windows_pack / CopyTranslator.py View on Github external
def __init__(self):

        # Collect events until released
        self.mouseListener = mouse.Listener(on_click=self.onLongClick)
        self.keyboard = Controller()

        self._default_value = {'author': 'Elliott Zheng',
                               'version': version,
                               'is_listen': False,
                               'is_copy': False,
                               'is_dete': False,
                               'stay_top': True,
                               'continus': False,
                               'is_main': True,
                               'pixel_size': 12
                               }
        self.value = self._default_value
        self.filepath = os.path.expanduser('~/copytranslator.json')
        self.load()
github josephp27 / ReduxAL / predicter.py View on Github external
def on_click_handler(x, y, button, pressed):
    # if shooting detected, tell puller we are enabled to kick off pulling down
    if button == mouse.Button.left and pressed:
        puller.enabled = True
    else:
        puller.enabled = False
github adsau59 / fishyboteso / fishy / engine / fullautofisher / engine.py View on Github external
import math
import cv2
import logging
import time

import numpy as np
import pywintypes
import pytesseract

from fishy.engine.IEngine import IEngine
from fishy.engine.window import Window
from pynput import keyboard, mouse

from fishy.helper import Config, hotkey

mse = mouse.Controller()
kb = keyboard.Controller()

rotate_by = 30


def sign(x):
    return -1 if x < 0 else 1


def get_crop_coods(window):
    Window.loop()
    img = window.get_capture()
    img = cv2.inRange(img, 0, 1)
    Window.loop_end()

    cnt, h = cv2.findContours(img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
github CopyTranslator / CopyTranslator / copyTranslator / config.py View on Github external
def __init__(self, setting):
        self.setting = setting
        self.mouseListener = mouse.Listener(on_click=self.setting.onLongClick)
        self._default_value = {'author': 'Elliott Zheng',
                               'version': version,
                               'is_listen': True,
                               'is_copy': False,
                               'is_dete': False,
                               'stay_top': False,
                               'continus': False,
                               'smart_dict': True,
                               'frame_mode': FrameMode.main,
                               'translator_type': TranslatorType.GOOGLE,
                               'font_size': 15,
                               'focus_x': 100,
                               'focus_y': 100,
                               'focus_height': 300,
                               'focus_width': 500,
                               'source': 'English',
github taojy123 / KeymouseGo / KeymouseGo.py View on Github external
def single_run(script_path, run_times=1):

    # python KeymouseGo.py scripts/0416_2342.txt 10
    # KeymouseGo.exe scripts\0416_2342.txt

    s = open(script_path, 'r').read()
    s = json.loads(s)
    steps = len(s)

    mouse_ctl = mouse.Controller()
    keyboard_ctl = keyboard.Controller()

    j = 0
    while j < run_times or run_times == 0:
        j += 1

        # Keep the same with Frame1.py:455, and remove code include `self`
        for i in range(steps):

            print(s[i])

            # for old style script
            if isinstance(s[i][0], str) and isinstance(s[i][3], int):
                s[i].insert(0, s[i][3])

            delay = s[i][0]
github silx-kit / silx / ci / close_popup.py View on Github external
"""
    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 josephp27 / ReduxAL / predicter.py View on Github external
if button == mouse.Button.left and pressed:
        puller.enabled = True
    else:
        puller.enabled = False


if __name__ == "__main__":
    print("press L to quit")
    # start our custom pull down listener
    threading.Thread(target=puller.pull_down, args=(False,)).start()

    # enable listening to keyboard and mouse events
    m.hook(mouse_handler)
    keyboard.on_release_key('e', keyboard_handler)
    keyboard.on_release_key('l', quit_handler)
    with mouse.Listener(on_click=on_click_handler) as listener:
        listener.join()