Monitor and control user input devices
Project description
pynput
This library allows you to control and monitor input devices.
Currently, only mouse input is supported.
Controlling the mouse
Use pynput.mouse.Controller like this:
from pynput.mouse import Controller, Listener
d = Controller()
# Read pointer position
print('The current pointer position is {0}'.format(
d.position))
# Set pointer position
d.position = (10, 20)
print('Now we have moved it to {0}'.format(
d.position))
# Move pointer relative to current position
d.move(5, -5)
# Press and release
d.press(d.Button.left)
d.release(d.Button.left)
# Double click; this is different from pressing and releasing twice on Mac
# OSX
d.click(d.Button.left, 2)
# Scroll two steps down
d.scroll(0, 2)
Monitoring the mouse
Use pynput.mouse.Listener like this:
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:
# Stop listener
return False
def on_scroll(dx, dy):
print('Scrolled {0}'.format(
(x, y)))
# Collect events until released
with Listener(
on_move=on_move,
on_click=on_click,
on_scroll=on_scroll) as l:
l.join()
A mouse listener is a threading.Thread, and all callbacks will be invoked from the thread.
Call pynput.mouse.Listener.stop from anywhere, or raise pynput.mouse.Listener.StopException or return False from a callback to stop the listener.
Release Notes
v0.2 - Initial Release
Support for controlling the mouse on Linux, Mac OSX and Windows.
Support for monitoring the mouse on Linux, Mac OSX and Windows.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pynput-0.2-py3-none-any.whl.
File metadata
- Download URL: pynput-0.2-py3-none-any.whl
- Upload date:
- Size: 49.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
126954b52e0a6cb1705dbf74855a78b8863460347a83f2d4e4c6f8ca6f76ee69
|
|
| MD5 |
fda5507ffc78348e93869e2f79fd6be4
|
|
| BLAKE2b-256 |
98ca0cc03fa6d48e6218b617c77e2748f48f80a302977607b242c268b8d13529
|
File details
Details for the file pynput-0.2-py2-none-any.whl.
File metadata
- Download URL: pynput-0.2-py2-none-any.whl
- Upload date:
- Size: 49.1 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6916bd589e84ee06d5d7b67e50a87761edd1da5f190eb8e8efd0ed0e726d600c
|
|
| MD5 |
fb1a3f073dadc0efdb5b739de15fc292
|
|
| BLAKE2b-256 |
37fd8c83aa6cef29af7f962b90f1f21fd316bacdbec781620174fe8410bd1792
|