Intercepting mouse & keyboard events using pynput Python library

Posted 4 months, 3 weeks ago
Intercepting mouse & keyboard events using pynput Python library
Python is an interpreted high-level general-purpose programming language. It focuses on code readability with its indentation. It can be used for Automation, IoT, Game Development, Desktop Applications, Web Development, Artificial Intelligence, Machine Learning & Data Science.
# install pynput library using command
pip install pynput

import pynput # try importing the library for confirming its installation

# now import required components from this library
from pynput.mouse import Button, Controller

# create an Controller instance for mouse
mouse = Controller()

# Now you can try experimenting with different functions provided by this library
print('Current Position is {0}'.format(

This library allows you to control and monitor input devices. Currently, mouse and keyboard input and monitoring are supported.

Try different functions provided in their documentation.