Python win32con.VK_F10 Examples

The following are 1 code examples of win32con.VK_F10(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module win32con , or try the search function .
Example #1
Source File: simple_screen_recorder.py    From Python-tools with MIT License 6 votes vote down vote up
def run(self):
        global EXIT  # 定义全局变量,这个可以在不同线程间共用。

        if not user32.RegisterHotKey(None, id2, 0, win32con.VK_F10):   # 注册快捷键F10并判断是否成功,该热键用于结束程序,且最好这么结束,否则影响下一次注册热键。
            print("Unable to register id", id2)

        # 以下为检测热键是否被按下,并在最后释放快捷键
        try:
            msg = ctypes.wintypes.MSG()
            while True:
                if user32.GetMessageA(ctypes.byref(msg), None, 0, 0) != 0:
                    if msg.message == win32con.WM_HOTKEY:
                        if msg.wParam == id2:
                            EXIT=True
                            return
                    user32.TranslateMessage(ctypes.byref(msg))
                    user32.DispatchMessageA(ctypes.byref(msg))
        finally:
            user32.UnregisterHotKey(None, id2)# 必须得释放热键,否则下次就会注册失败,所以当程序异常退出,没有释放热键,
                                              # 那么下次很可能就没办法注册成功了,这时可以换一个热键测试