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

我们两清 提交于 2019-12-17 20:14:24

问题


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?


回答1:


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)



回答2:


Install pywin32 for Python 3.x

Here is the example for checking capslock state.

from win32api import GetKeyState 
from win32con import VK_CAPITAL 
GetKeyState(VK_CAPITAL)


来源:https://stackoverflow.com/questions/21160100/python-3-x-getting-the-state-of-caps-lock-num-lock-scroll-lock-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!