pywinauto.win32_hooks

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:
  • WH_MOUSE_LL
  • WH_KEYBOARD_LL

More detailed documentation about Windows hooks can be found in MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/ms632589.aspx

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

is_hooked()

Verify if any of hooks are active

listen()

Listen for events

stop()

Stop the listening loop

unhook_keyboard()

Unhook keyboard events

unhook_mouse()

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