WH_MOUSE_LL does hook XButtons and PyHook's dll passes it through to python, but the HookManager on the python side ignores them. However, you can skip HookManager and use the cpyHook interface directly.
This example prints xbutton events to the console as they are pressed and exits when the left mouse button is pressed:
from pyHook import cpyHook, HookConstants
import pythoncom
import ctypes
user32 = ctypes.windll.user32
XBUTTON1 = 0x0001
XBUTTON2 = 0x0002
wm = { 0x020B: "WM_XBUTTONDOWN", 0x020C: "WM_XBUTTONUP", 0x0201: "WM_LBUTTONDOWN", }
def mouse_handler(msg, x, y, data, flags, time, hwnd, window_name):
name = wm.get(msg, None)
if name:
xb = data >> 16 # high word indicates which xbutton
print(name, xb & XBUTTON1, xb & XBUTTON2)
if name == "WM_LBUTTONDOWN":
user32.PostQuitMessage(0)
return True # True = pass the event to other handlers
try:
cpyHook.cSetHook(HookConstants.WH_MOUSE_LL, mouse_handler)
pythoncom.PumpMessages() # returns on WM_QUIT
finally:
cpyHook.cUnhook(HookConstants.WH_MOUSE_LL)