python类MSG的实例源码

real_hotkeys.py 文件源码 项目:petronia 作者: groboclown 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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)
funcs_any_win.py 文件源码 项目:petronia 作者: groboclown 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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
global_hotkey_win.py 文件源码 项目:paste2box 作者: rokups 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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)
mouselogger.py 文件源码 项目:purelove 作者: hucmosin 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
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()
mouselogger.py 文件源码 项目:OSPTF 作者: xSploited 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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()
tkinput.py 文件源码 项目:ATX 作者: NetEaseGame 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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.
mouselogger.py 文件源码 项目:pupy 作者: ru-faraon 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
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()
tkinput.py 文件源码 项目:AutomatorX 作者: xiaoyaojjian 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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.
client.py 文件源码 项目:gdog 作者: maldevel 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def startKeyLog(self):                                                                
        msg = MSG()
        ctypes.windll.user32.GetMessageA(ctypes.byref(msg),0,0,0)
client.py 文件源码 项目:canisrufus 作者: maldevel 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def startKeyLog(self):                                                                
        msg = MSG()
        ctypes.windll.user32.GetMessageA(ctypes.byref(msg),0,0,0)
hooking.py 文件源码 项目:Scriptology 作者: JohnTroony 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def startKeyLog():
    msg = MSG()
    user32.GetMessageA(byref(msg), 0, 0, 0)
tkinput.py 文件源码 项目:Sleep-Early 作者: AliNL 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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.
ddeclient.py 文件源码 项目:pyzos 作者: indranilsinharoy 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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)
client.py 文件源码 项目:dicerosbicornis 作者: maldevel 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def startKeyLog(self):                                                                
        msg = MSG()
        ctypes.windll.user32.GetMessageA(ctypes.byref(msg),0,0,0)
threaded_explicit_hotkeys.py 文件源码 项目:petronia 作者: groboclown 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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))


问题


面经


文章

微信
公众号

扫码关注公众号