Python 3.x - Getting the state of caps-lock/num-lock/scroll-lock on Windows

后端 未结 2 1231
被撕碎了的回忆
被撕碎了的回忆 2020-12-06 18:15

Just as the question asks, I know this is possible on Linux, but I couldn\'t find anything recent for Windows. Is it even possible?

2条回答
  •  情歌与酒
    2020-12-06 19:16

    You can use ctypes to load user32.dll and then call GetKeyState with nVirtKey = VK_CAPITAL (0x14)

    def get_capslock_state():
        import ctypes
        hllDll = ctypes.WinDLL ("User32.dll")
        VK_CAPITAL = 0x14
        return hllDll.GetKeyState(VK_CAPITAL)
    

提交回复
热议问题