CMPFUNC = CFUNCTYPE(c_int, c_int, c_int, POINTER(c_void_p))
pointer = CMPFUNC(low_level_handler)
hook_id = windll.user32.SetWindowsHookExA(win32con.WH_KEYBOARD_LL, pointer,
    win32api.GetModuleHandle(None), 0)
atexit.register(windll.user32.UnhookWindowsHookEx, hook_id)
while True:
    msg = win32gui.GetMessage(None, 0, 0)
win32gui.TranslateMessage(byref(msg))
win32gui.DispatchMessage(byref(msg))
if __name__ == '__main__':

    def print_event(e):
        print(e)
handlers.append(print_event)
listen()
Применение низкоуровневых перехватчиков клавиатуры с помощью Python и SetWindowsHookExA