Skip to main content

Monitor and control user input devices

Project description


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(

# Set pointer position
d.position = (10, 20)
print('Now we have moved it to {0}'.format(

# Move pointer relative to current position
d.move(5, -5)

# Press and release

# Double click; this is different from pressing and releasing twice on Mac
# OSX, 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_scroll=on_scroll) as l:

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

pynput-0.2-py3-none-any.whl (49.0 kB view hashes)

Uploaded Python 3

pynput-0.2-py2-none-any.whl (49.1 kB view hashes)

Uploaded Python 2

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page