Name : python3-pynput
| |
Version : 1.4.2
| Vendor : obs://build_opensuse_org/home:lrupp
|
Release : lp156.1.1
| Date : 2024-02-12 10:49:12
|
Group : Development/Languages/Python
| Source RPM : python-pynput-1.4.2-lp156.1.1.src.rpm
|
Size : 0.57 MB
| |
Packager : https://www_suse_com/
| |
Summary : Monitor and control user input devices
|
Description :
pynput ======
This library allows you to control and monitor input devices.
Currently, mouse and keyboard input and monitoring are supported.
See `here < https://pynput.readthedocs.io/en/latest/>`_ for the full documentation.
Controlling the mouse ---------------------
Use ``pynput.mouse.Controller`` like this::
from pynput.mouse import Button, Controller
mouse = Controller()
print(\'The current pointer position is {0}\'.format( mouse.position))
mouse.position = (10, 20) print(\'Now we have moved it to {0}\'.format( mouse.position))
mouse.move(5, -5)
mouse.press(Button.left) mouse.release(Button.left)
mouse.click(Button.left, 2)
mouse.scroll(0, 2)
Monitoring the mouse --------------------
Use ``pynput.mouse.Listener`` like this::
from pynput import mouse
def on_move(x, y): print(\'Pointer moved to {0}\'.format( (x, y)))
def on_click(x, y, button, pressed): print(\'{0} at {1}\'.format( \'Pressed\' if pressed else \'Released\', (x, y))) if not pressed: return False
def on_scroll(x, y, dx, dy): print(\'Scrolled {0} at {1}\'.format( \'down\' if dy < 0 else \'up\', (x, y)))
with mouse.Listener( on_move=on_move, on_click=on_click, on_scroll=on_scroll) as listener: listener.join()
listener = mouse.Listener( on_move=on_move, on_click=on_click, on_scroll=on_scroll) listener.start()
A mouse listener is a ``threading.Thread``, and all callbacks will be invoked from the thread.
Call ``pynput.mouse.Listener.stop`` from anywhere, raise ``StopException`` or return ``False`` from a callback to stop the listener.
The mouse listener thread ~~~~~~~~~~~~~~~~~~~~~~~~~
The listener callbacks are invoked directly from an operating thread on some platforms, notably *Windows*.
This means that long running procedures and blocking operations should not be invoked from the callback, as this risks freezing input for all processes.
A possible workaround is to just dispatch incoming messages to a queue, and let a separate thread handle them.
Handling mouse listener errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If a callback handler raises an exception, the listener will be stopped. Since callbacks run in a dedicated thread, the exceptions will not automatically be reraised.
To be notified about callback errors, call ``Thread.join`` on the listener instance::
from pynput import mouse
class MyException(Exception): pass
def on_click(x, y, button, pressed): if button == mouse.Button.left: raise MyException(button)
with mouse.Listener( on_click=on_click) as listener: try: listener.join() except MyException as e: print(\'{0} was clicked\'.format(e.args[0]))
Controlling the keyboard ------------------------
Use ``pynput.keyboard.Controller`` like this::
from pynput.keyboard import Key, Controller
keyboard = Controller()
keyboard.press(Key.space) keyboard.release(Key.space)
keyboard.press(\'a\') keyboard.release(\'a\')
keyboard.press(\'A\') keyboard.release(\'A\') with keyboard.pressed(Key.shift): keyboard.press(\'a\') keyboard.release(\'a\')
keyboard.type(\'Hello World\')
Monitoring the keyboard -----------------------
Use ``pynput.keyboard.Listener`` like this::
from pynput import keyboard
def on_press(key): try: print(\'alphanumeric key {0} pressed\'.format( key.char)) except AttributeError: print(\'special key {0} pressed\'.format( key))
def on_release(key): print(\'{0} released\'.format( key)) if key == keyboard.Key.esc: return False
with keyboard.Listener( on_press=on_press, on_release=on_release) as listener: listener.join()
listener = mouse.Listener( on_press=on_press, on_release=on_release) listener.start()
A keyboard listener is a ``threading.Thread``, and all callbacks will be invoked from the thread.
Call ``pynput.keyboard.Listener.stop`` from anywhere, raise ``StopException`` or return ``False`` from a callback to stop the listener.
The ``key`` parameter passed to callbacks is a ``pynput.keyboard.Key``, for special keys, a ``pynput.keyboard.KeyCode`` for normal alphanumeric keys, or just ``None`` for unknown keys.
The keyboard listener thread ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The listener callbacks are invoked directly from an operating thread on some platforms, notably *Windows*.
This means that long running procedures and blocking operations should not be invoked from the callback, as this risks freezing input for all processes.
A possible workaround is to just dispatch incoming messages to a queue, and let a separate thread handle them.
Handling keyboard listener errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If a callback handler raises an exception, the listener will be stopped. Since callbacks run in a dedicated thread, the exceptions will not automatically be reraised.
To be notified about callback errors, call ``Thread.join`` on the listener instance::
from pynput import keyboard
class MyException(Exception): pass
def on_press(key): if key == keyboard.Key.esc: raise MyException(key)
with keyboard.Listener( on_press=on_press) as listener: try: listener.join() except MyException as e: print(\'{0} was pressed\'.format(e.args[0]))
|
RPM found in directory: /packages/linux-pbone/ftp5.gwdg.de/pub/opensuse/repositories/home:/lrupp/15.6/noarch |