hotkey_5.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:petronia 作者: groboclown 项目源码 文件源码
def hook_keyboard(callback):
    handle = None

    def low_level_callback(code, rparam, lparam):
        try:
            key_code = 0xFFFFFFFF & lparam[0]  # key code
            callback(key_code, rparam & 0xFFFFFFFF)
        finally:
            return CallNextHookEx(handle, code, rparam, lparam)
    # The really big problem is the callback_pointer.
    # Once it goes out of scope, it is destroyed
    callback_pointer = CFUNCTYPE(c_int, c_int, wintypes.HINSTANCE, POINTER(c_void_p))(low_level_callback)
    __CALLBACK_POINTERS.append(callback_pointer)
    handle = SetWindowsHookExA(WH_KEYBOARD_LL, callback_pointer, GetModuleHandleA(None), 0)
    atexit.register(UnhookWindowsHookEx, handle)
    return handle
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号