WinAPI: How to get the caps lock state?

SmRndGuy picture SmRndGuy · Dec 16, 2012 · Viewed 20.5k times · Source

How can get whether Caps Lock is on or off? I tried to search it but all I'm finding is how to toggle or turn it on/off which is exactly opposite of what I'm looking for.

I'm trying to do that in both C++ and Delphi.
Please help

Answer

Mattias Josefsson picture Mattias Josefsson · Dec 16, 2012

I found this link and the code snippet below that might help you

if ((GetKeyState(VK_CAPITAL) & 0x0001)!=0)
  AfxMessageBox("Caps Lock ON!");
else
  AfxMessageBox("Caps Lock OFF!");