This site hosted by Free.ProHosting.com
Google

How can I check the state of Num, Caps, and Scoll Lock?

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

Is it possible to know the state of -lock keys such as Num Lock, Caps Lock or Scroll Lock?
 
 1.
  Start a new project using File | New Application.
 
 2.
  Add three (3) Shapes and set their Brush->Color to clBlack.
 
 3.
  Edit the OnShow event of your form:
 
void __fastcall TForm1::FormShow(TObject *Sender)
{
    // Num Lock
    if(GetKeyState(VK_NUMLOCK))
        Shape1->Brush->Color = clYellow;
    // Caps Lock
    if(GetKeyState(VK_CAPITAL))
        Shape2->Brush->Color = clYellow;
    // Scroll Lock
    if(GetKeyState(VK_SCROLL))
        Shape3->Brush->Color = clYellow;
}
 
The Win32 API function GetKeyState returns the current state of the specified key.

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