This site hosted by Free.ProHosting.com
Google

How can I change the state of Caps Lock?

Applies To: C++Builder 1 or higher
Category: Knowledge Base

Getting the state of Caps Lock as shown in How can I check the state of Num, Caps, and Scroll Lock? was quite easy. I need now to change this state. Is it possible?
 
 1.
  Start a new project using File | New Application.
 
 2.
  Add two (2) Buttons.
 
 3.
  Set their OnClick event to:
 
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    // Enable Caps Lock
    unsigned char key[256];
    GetKeyboardState(key);
    key[VK_CAPITAL] = 1;
    SetKeyboardState(key);
}
 
void __fastcall TForm1::Button2Click(TObject *Sender)
{
    // Disable Caps Lock
    unsigned char key[256];
    GetKeyboardState(key);
    key[VK_CAPITAL] = 0;
    SetKeyboardState(key);
}
 
The Win32 API function SetKeyboardState allows you to change this state.

C++Builder Developer's Network
Copyright © Yoto Yotov