Discussion:
How to look at CAPS LOCK & NUM LOCK
(too old to reply)
Derek Harvey
2008-07-18 17:59:10 UTC
Permalink
Can someone tell me please how I can inspect in my program the state of Caps
Lock and Num Lock (so I can do SendKeys to change it to what I want it to
be. (Primarily to set Caps Lock off before inviting password entry.)

Thanks
Derek
Remy Lebeau (TeamB)
2008-07-18 18:38:13 UTC
Permalink
Post by Derek Harvey
Can someone tell me please how I can inspect in my program the state of
Caps Lock and Num Lock (so I can do SendKeys to change it to what I want
it to be. (Primarily to set Caps Lock off before inviting password entry.)
Look at the Win32 API GetKeyState() and Get/SetKeyboardState() functions.


Gambit
Derek Harvey
2008-07-19 09:50:00 UTC
Permalink
Thanks. SetKeyboardState says it cannot be used to toggle CAPS Lock, etc.,
but it did point me to keybd_event which unusually helpfully includes an
example that can be adapted to what I want, I think.
The example is a little confusing, however. The definition of keybd_event
function says that parameter bScan is not used, but the example gives it a
value of 0x45 without explanation.

Can you explain it, please? But I will experiment with it anyway.

Derek
Post by Remy Lebeau (TeamB)
Post by Derek Harvey
Can someone tell me please how I can inspect in my program the state of
Caps Lock and Num Lock (so I can do SendKeys to change it to what I want
it to be. (Primarily to set Caps Lock off before inviting password entry.)
Look at the Win32 API GetKeyState() and Get/SetKeyboardState() functions.
Gambit
Derek Harvey
2008-07-19 22:43:21 UTC
Permalink
Once I found the (non-obvious) VK_ code for CAPS LOCK it was
straightforward.
The following little function sets CAPS LOCK unconditionally OFF
void __fastcall KillCaps( void ) {
BYTE keyState[256];
GetKeyboardState((LPBYTE)&keyState);
if ( keyState[VK_CAPITAL] & 1 ) {
keybd_event( VK_CAPITAL, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 );
keybd_event( VK_CAPITAL, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0 );
}
}
I have what I want and thanks to all for the help.
Derek
Post by Derek Harvey
Thanks. SetKeyboardState says it cannot be used to toggle CAPS Lock, etc.,
but it did point me to keybd_event which unusually helpfully includes an
example that can be adapted to what I want, I think.
The example is a little confusing, however. The definition of keybd_event
function says that parameter bScan is not used, but the example gives it a
value of 0x45 without explanation.
Can you explain it, please? But I will experiment with it anyway.
Derek
Post by Remy Lebeau (TeamB)
Post by Derek Harvey
Can someone tell me please how I can inspect in my program the state of
Caps Lock and Num Lock (so I can do SendKeys to change it to what I want
it to be. (Primarily to set Caps Lock off before inviting password entry.)
Look at the Win32 API GetKeyState() and Get/SetKeyboardState() functions.
Gambit
Michael Brazee
2008-07-18 18:38:21 UTC
Permalink
Derek,

You also can just UpperCase the contents entered into the edit box before
comparing to or assigning to the password field.
AnsiString UpperPassword = UpperCase(PasswordEditBox.Text);

HTH,

Mike
Post by Derek Harvey
Can someone tell me please how I can inspect in my program the state of
Caps Lock and Num Lock (so I can do SendKeys to change it to what I want
it to be. (Primarily to set Caps Lock off before inviting password entry.)
Thanks
Derek
Derek Harvey
2008-07-19 09:51:06 UTC
Permalink
Thanks, but that would defeat the aim of good mixed-case passwords.
Derek
Post by Michael Brazee
Derek,
You also can just UpperCase the contents entered into the edit box before
comparing to or assigning to the password field.
AnsiString UpperPassword = UpperCase(PasswordEditBox.Text);
HTH,
Mike
Post by Derek Harvey
Can someone tell me please how I can inspect in my program the state of
Caps Lock and Num Lock (so I can do SendKeys to change it to what I want
it to be. (Primarily to set Caps Lock off before inviting password entry.)
Thanks
Derek
JohnC
2008-07-18 18:56:44 UTC
Permalink
Why bother to inspect it?
Just set Caps Lock off and be done with it.
John
Post by Derek Harvey
Can someone tell me please how I can inspect in my program the state of
Caps Lock and Num Lock (so I can do SendKeys to change it to what I want
it to be. (Primarily to set Caps Lock off before inviting password entry.)
Thanks
Derek
Derek Harvey
2008-07-19 09:56:32 UTC
Permalink
Thanks. Yes, I would if I could but I cannot find how to do it. All the
functions I have found up to now can only toggle (i.e. invert the state of)
the NUMS Lock and CAPS LOCK keys.
If you do know how to unconditionally set it OFF could you give the code,
please. (But as in earlier replies in the thread I have found a solution
anyway so do not spend much time on it.)
Derek
Post by JohnC
Why bother to inspect it?
Just set Caps Lock off and be done with it.
John
Post by Derek Harvey
Can someone tell me please how I can inspect in my program the state of
Caps Lock and Num Lock (so I can do SendKeys to change it to what I want
it to be. (Primarily to set Caps Lock off before inviting password entry.)
Thanks
Derek
Loading...