Python ctypes.wintypes 模块,MSG 实例源码

我们从Python开源项目中,提取了以下15个代码示例,用于说明如何使用ctypes.wintypes.MSG

项目:petronia    作者:groboclown    | 项目源码 | 文件源码
def hook_keyboard():
    hotkey_list = register_hotkeys()

    try:
        message = wintypes.MSG()
        while True:
            msg = windll.user32.GetMessageW(byref(message), 0, 0, 0)
            print("found message {0}".format(msg))
            if msg == -1:
                sys.exit(0)
            elif msg == 0:  # WM_QUIT
                sys.exit(0)
            else:
                windll.user32.TranslateMessage(byref(message))
                windll.user32.DispatchMessageW(byref(message))

    finally:
        unregister_hotkeys(hotkey_list)
项目:petronia    作者:groboclown    | 项目源码 | 文件源码
def shell__pump_messages(on_exit_callback=None):
    assert on_exit_callback is None or callable(on_exit_callback)
    message = wintypes.MSG()
    while True:
        msg = GetMessageW(byref(message), 0, 0, 0)
        if msg <= 0:
            # print("DEBUG quit message in queue")
            # 0 means WM_QUIT, < 0 means error
            if on_exit_callback is not None and callable(on_exit_callback):
                on_exit_callback()
            else:
                sys.exit(0)
        else:
            TranslateMessage(byref(message))
            DispatchMessageW(byref(message))


# see https://msdn.microsoft.com/en-us/library/windows/desktop/ms644967(v=vs.85).aspx
项目:paste2box    作者:rokups    | 项目源码 | 文件源码
def _translate_message_hook(self, pmsg: MSG):
        msg = pmsg.contents
        if msg.message == WM_HOTKEY:
            keycode = (msg.lParam >> 16) & 0xFFFF
            modifiers = msg.lParam & 0xFFFF
            key = (keycode, modifiers)
            if key in self.shortcuts:
                QTimer.singleShot(0, self.shortcuts[key])
                return False
        return self._TranslateMessageReal(pmsg)
项目:purelove    作者:hucmosin    | 项目源码 | 文件源码
def run(self):
        if self.install_hook():
            #print "mouselogger installed"
            pass
        else:
            raise RuntimeError("couldn't install mouselogger")
        msg = MSG()
        user32.GetMessageA(byref(msg),0,0,0)
        while not self.stopped:
            time.sleep(1)
        self.uninstall_hook()
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def run(self):
        if self.install_hook():
            #print "mouselogger installed"
            pass
        else:
            raise RuntimeError("couldn't install mouselogger")
        msg = MSG()
        user32.GetMessageA(byref(msg),0,0,0)
        while not self.stopped:
            time.sleep(1)
        self.uninstall_hook()
项目:ATX    作者:NetEaseGame    | 项目源码 | 文件源码
def handle_hotkey(root, callback):
        msg = wintypes.MSG()
        if windll.user32.GetMessageA(byref(msg), None, 0, 0) != 0:
            if msg.message == win32con.WM_HOTKEY:
                if msg.wParam == 1:
                    print 'Hotkey triggered!'
                    callback()
        windll.user32.TranslateMessage(byref(msg))
        windll.user32.DispatchMessageA(byref(msg))
        root.after(1, handle_hotkey, root, callback)

    # hotkey map refs: https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
    # not yet used here.
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def run(self):
        if self.install_hook():
            #print "mouselogger installed"
            pass
        else:
            raise RuntimeError("couldn't install mouselogger")
        msg = MSG()
        user32.GetMessageA(byref(msg),0,0,0)
        while not self.stopped:
            time.sleep(1)
        self.uninstall_hook()
项目:AutomatorX    作者:xiaoyaojjian    | 项目源码 | 文件源码
def handle_hotkey(root, callback):
        msg = wintypes.MSG()
        if windll.user32.GetMessageA(byref(msg), None, 0, 0) != 0:
            if msg.message == win32con.WM_HOTKEY:
                if msg.wParam == 1:
                    print 'Hotkey triggered!'
                    callback()
        windll.user32.TranslateMessage(byref(msg))
        windll.user32.DispatchMessageA(byref(msg))
        root.after(1, handle_hotkey, root, callback)

    # hotkey map refs: https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
    # not yet used here.
项目:gdog    作者:maldevel    | 项目源码 | 文件源码
def startKeyLog(self):                                                                
        msg = MSG()
        ctypes.windll.user32.GetMessageA(ctypes.byref(msg),0,0,0)
项目:canisrufus    作者:maldevel    | 项目源码 | 文件源码
def startKeyLog(self):                                                                
        msg = MSG()
        ctypes.windll.user32.GetMessageA(ctypes.byref(msg),0,0,0)
项目:Scriptology    作者:JohnTroony    | 项目源码 | 文件源码
def startKeyLog():
    msg = MSG()
    user32.GetMessageA(byref(msg), 0, 0, 0)
项目:Sleep-Early    作者:AliNL    | 项目源码 | 文件源码
def handle_hotkey(root, callback):
        msg = wintypes.MSG()
        if windll.user32.GetMessageA(byref(msg), None, 0, 0) != 0:
            if msg.message == win32con.WM_HOTKEY:
                if msg.wParam == 1:
                    # print 'Hotkey triggered!'
                    callback()
        windll.user32.TranslateMessage(byref(msg))
        windll.user32.DispatchMessageA(byref(msg))
        root.after(1, handle_hotkey, root, callback)

    # hotkey map refs: https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
    # not yet used here.
项目:pyzos    作者:indranilsinharoy    | 项目源码 | 文件源码
def WinMSGLoop():
    """Run the main windows message loop."""
    LPMSG = POINTER(MSG)
    LRESULT = c_ulong
    GetMessage = get_winfunc("user32", "GetMessageW", BOOL, (LPMSG, HWND, UINT, UINT))
    TranslateMessage = get_winfunc("user32", "TranslateMessage", BOOL, (LPMSG,))
    # restype = LRESULT
    DispatchMessage = get_winfunc("user32", "DispatchMessageW", LRESULT, (LPMSG,))

    msg = MSG()
    lpmsg = byref(msg)
    while GetMessage(lpmsg, HWND(), 0, 0) > 0:
        TranslateMessage(lpmsg)
        DispatchMessage(lpmsg)
项目:dicerosbicornis    作者:maldevel    | 项目源码 | 文件源码
def startKeyLog(self):                                                                
        msg = MSG()
        ctypes.windll.user32.GetMessageA(ctypes.byref(msg),0,0,0)
项目:petronia    作者:groboclown    | 项目源码 | 文件源码
def hook_keyboard():
    def handler(key_code, event_code):
        print("{0} {1}".format(hex(key_code), hex(event_code)))
    handle = [None]

    def low_level_callback(code, rparam, lparam):
        try:
            key_code = 0xFFFFFFFF & lparam[0]  # key code
            handler(key_code, rparam & 0xFFFFFFFF)
        finally:
            return CallNextHookEx(handle[0], code, rparam, lparam)

    callback_pointer = CFUNCTYPE(c_int, c_int, wintypes.HINSTANCE, POINTER(c_void_p))(low_level_callback)
    handle[0] = SetWindowsHookExA(WH_KEYBOARD_LL, callback_pointer, GetModuleHandleA(None), 0)
    atexit.register(UnhookWindowsHookEx, handle[0])

    # Message pumper
    message = wintypes.MSG()
    while True:
        msg = GetMessageW(byref(message), 0, 0, 0)
        if msg == -1:
            UnhookWindowsHookEx(handle[0])
            sys.exit(0)

        elif msg == 0:  # GetMessage return 0 only if WM_QUIT
            sys.exit(0)
        else:
            TranslateMessage(byref(message))
            DispatchMessageW(byref(message))