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.

About these ads

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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Follow

Get every new post delivered to your Inbox.

Join 37 other followers

%d bloggers like this: