pynput Package Documentation

This library allows you to control and monitor input devices.

It contains subpackages for each type of input device supported:

pynput.mouse
Contains classes for controlling and monitoring a mouse or trackpad.
pynput.keyboard
Contains classes for controlling and monitoring the keyboard.

All modules mentioned above are automatically imported into the pynput package. To use any of them, import them from the main package:

from pynput import mouse, keyboard

Forcing a specific backend

pynput attempts to use the backend suitable for the current platform, but this automatic choice is possible to override.

If the environment variables $PYNPUT_BACKEND_KEYBOARD or $PYNPUT_BACKEND are set, their value will be used as backend name for the keyboard classes, and if $PYNPUT_BACKEND_KEYBOARD or $PYNPUT_BACKEND are set, their value will be used as backend name for the mouse classes.

Available backends are:

  • darwin, the default for macOS.
  • win32, the default for Windows.
  • xorg, the default for other operating systems.
  • dummy, a non-functional, but importable, backend.