Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I capture Capslock / Shift key presses?

I just discovered that the caps lock and shift key (and probably some more of the keys) affect all of the keyboards connected to the computer. (one of the hazards of testing a program that I coded, I only have two hands so it took me ages to realize a problem like this) So separating the keystrokes is fine, but the shift/caps locks drives everything crazy (When one user shifts to capitalize, all users' input at that moment are capitalized as well)

Can I capture Capslock and Shift keypress in FormKeyPress? Anywhere else for that matter?
Can I save a Shift keypress? (so I can properly apply the 'shift' to the respective user input)

Any other suggestion to solve this problem is welcome as well.

like image 528
Dian Avatar asked Aug 13 '10 08:08

Dian


1 Answers

to check if shift ley is down try this:

if GetKeyState(VK_SHIFT)<0 //tests if shiftkey is down
 then ShowMessage('shift key is down'');

and to detect if caps lock is on try this:

if Odd(GetKeyState(VK_CAPITAL)) //tests if caps lock is on
then showmessage('caps lock is on');

and if you want to check status of both shift and capslock :

      if Odd(GetKeyState(VK_CAPITAL)) then 
            if GetKeyState(VK_SHIFT)<0 then 
            showmessage('capslock is on and shift key is down too')
           else
          showmessage('capslock is on but shift key is NOT down');

getkeystate is a windows api function you can read more about it here

like image 162
Omair Iqbal Avatar answered Oct 16 '22 00:10

Omair Iqbal