How can I programmatically switch CAPSLOCK or prevent it from switching from the keyboard?

I have a program written in C ++ and working on windows. I am allowing the user to plug in the CAPSLOCK key, so it would be nice if every time they pressed it, they also didn't toggle their CAPSLOCK state.

I haven't found a way to "capture" the CAPSLOCK message to prevent windows from registering it. It looks like by the time the WM_KEYDOWN message was received, the indicator on my keyboard had already switched.

I found this suggested code :

keybd_event( VK_CAPITAL, 0x3a, KEYEVENTF_EXTENDEDKEY, 0 );
keybd_event( VK_CAPITAL, 0x3a, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0 );

      

But that won't work. This somehow caused the indicator to flicker and doesn't seem to affect the CAPSLOCK state at all.

+3


source to share


1 answer


Try in reverse order:



keybd_event( VK_CAPITAL, 0x3a, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0 );
keybd_event( VK_CAPITAL, 0x3a, KEYEVENTF_EXTENDEDKEY, 0 );

      

0


source







All Articles