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()
Applying low-level keyboard hooks with Python and SetWindowsHookExA