Pynput (Robocorp Fork)
This is a maintained fork of the original `pynput` library (by TheMouseOrTheKeyboard), designed specifically for Robocorp's automation needs. It provides cross-platform control and monitoring of user input devices like keyboards and mice, essential for Robotic Process Automation (RPA). Version 5.0.0, released recently, focuses on Python 3.10+ compatibility and Linux environment improvements. Releases align with Robocorp's product development, typically with minor versions for bug fixes and improvements.
Warnings
- gotcha Permissions are required for controlling input devices. On macOS, grant 'Accessibility' permissions to your terminal or IDE. On Linux (X11), ensure your user has appropriate X server access.
- gotcha When using `Listener` objects, `listener.join()` will block the current thread. For non-blocking behavior in GUI applications or concurrent tasks, run listeners in separate threads or manage them asynchronously.
- breaking Older versions of the `pynput-robocorp-fork` (prior to 5.0.0) may have had compatibility issues with Python 3.10 and newer versions.
- gotcha This is a fork of the original `pynput` library. While it maintains a high degree of API compatibility, it may have subtle differences, specific fixes, or updated dependencies not present in the original `pynput`. Avoid mixing `pynput` and `pynput-robocorp-fork` in the same environment or project.
Install
-
pip install pynput-robocorp-fork
Imports
- Controller
from pynput.mouse import Controller
from pynput.keyboard import Controller
- Listener
from pynput import Listener
from pynput.keyboard import Listener
- Key
from pynput.keyboard import Key
- Button
from pynput.mouse import Button
Quickstart
from pynput.keyboard import Controller, Key
import time
keyboard = Controller()
print("Typing 'Hello World'...")
keyboard.type('Hello World')
time.sleep(1)
print("Pressing Enter...")
keyboard.press(Key.enter)
keyboard.release(Key.enter)
time.sleep(1)
print("Pressing Ctrl+C...")
with keyboard.pressed(Key.ctrl):
keyboard.press('c')
keyboard.release('c')
print("Keyboard actions completed.")