Windows global hooks in pure Python

The implementation uses foreign function interface (FFI) provided by standard Python module ctypes and inspired by pyHook, pyhooked and other similar modules (the code was re-written from scratch). It tends to be a superset of pyHook but in pure Python only so it doesn’t require compilation.

Current set of hooks implemented:

More detailed documentation about Windows hooks can be found in MSDN:

This module can be used as a stand alone or along with pywinauto. The fork of this code (at some moment) was used in standalone library pyhooked 0.8 maintained by Ethan Smith.

class pywinauto.win32_hooks.Hook

Hook for low level keyboard and mouse events

hook(keyboard=True, mouse=False)

Hook mouse and/or keyboard events


Verify if any of hooks are active


Listen for events


Stop the listening loop


Unhook keyboard events


Unhook mouse events

class pywinauto.win32_hooks.KeyboardEvent(current_key=None, event_type=None, pressed_key=None)

Created when a keyboard event happened

class pywinauto.win32_hooks.MouseEvent(current_key=None, event_type=None, mouse_x=0, mouse_y=0)

Created when a mouse event happened