Skip to content Skip to sidebar Skip to footer

Python 3.x - Getting The State Of Caps-lock/num-lock/scroll-lock On Windows

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?

Solution 1:

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

def get_capslock_state():
    importctypeshllDll= ctypes.WinDLL ("User32.dll")
    VK_CAPITAL = 0x14return hllDll.GetKeyState(VK_CAPITAL)

Solution 2:

Install pywin32 for Python 3.x

Here is the example for checking capslock state.

from win32api importGetKeyStatefrom win32con importVK_CAPITALGetKeyState(VK_CAPITAL)

Post a Comment for "Python 3.x - Getting The State Of Caps-lock/num-lock/scroll-lock On Windows"