Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 677
EnronEvolved Avatar asked Jan 16 '14 11:01

EnronEvolved


2 Answers

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)
like image 77
Jakob Bowyer Avatar answered Sep 16 '22 11:09

Jakob Bowyer


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)
like image 20
Abhijit Avatar answered Sep 19 '22 11:09

Abhijit