How to check the Caps Lock is ON or OFF

19 01 2009

description9

 

 

Sometimes we need to get the status of the keys in the keyboard. For example we need to check whether the Caps Lock key is on or not programmatically.

howcanidoit17

 

 

This could be established by using the Windows API function GetKeyState. Actually this function retrieves the status of the spcified virtual key. There have a virtual-key codes corresponding to each keys in the keyboard.

mycodesnippet6

 

 

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

mynote10

 

 

We could also use the function GetAsyncKeyState for this purpose.


Actions

Information

4 responses

8 07 2011
Mitchell de Rijcke

Thank you very much!

30 09 2012
lol

TY

4 11 2013
serak

is it possible to do this in javascript?

6 11 2013

Leave a comment