Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinAPI: How to get the caps lock state?

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

like image 429
SmRndGuy Avatar asked Dec 16 '12 20:12

SmRndGuy


People also ask

How do you trigger Caps Lock?

Pressing the key with the magnifying glass while also pressing the Alt key toggles Caps Lock on and off. You'll know that Caps Lock is on when you type some letters and they are all capitals. Press this keyboard combination again to turn Caps Lock back off.

How do you turn off Caps Lock in a remote session?

In the remote Windows system, click the Start button, located in Windows Taskbar. Go to Accessories > Ease of Access / or Accessibility sub folder. Open Microsoft On-Screen Keyboard software. Click Caps Lock (key in remote On-Screen Keyboard) to toggle the remote keyboard status (unlock caps).

How do I know if Num Lock is on?

Simplest method: Type one character, then press 4 on num pad: If a character is typed in the field, then num lock is on. If cursor moves to left then num lock is off.


1 Answers

You want the GetKeyState() function:

http://msdn.microsoft.com/en-us/library/ms646301(VS.85).aspx

with the VK_CAPITAL key code. Rest of the virtual key codes are here:

http://technet.microsoft.com/en-us/subscriptions/index/dd375731(v=vs.85).aspx

like image 140
HerrJoebob Avatar answered Sep 20 '22 04:09

HerrJoebob