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 HarveyThanks. 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 HarveyCan 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