5

Delphi 2010 Enterprise

How can I automatically turn the CapsLock on when the virtual keyboard is displayed.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
Donald Adams
  • 147
  • 1
  • 10

1 Answers1

6

Try this on your FormCreate:

procedure TForm1.FormCreate(Sender: TObject);
var
  MyKeys: array of tagInput;
begin
  setLength(MyKeys, 2);
  MyKeys[0].Itype:=INPUT_KEYBOARD;
  MyKeys[0].ki.wVk:=VK_CAPITAL;
  MyKeys[0].ki.wScan:=0;
  MyKeys[0].ki.dwFlags:=4;
  MyKeys[0].ki.time:=0;
  MyKeys[0].ki.dwExtraInfo:=0;

  MyKeys[1].Itype:=INPUT_KEYBOARD;
  MyKeys[1].ki.wVk:=VK_CAPITAL;
  MyKeys[1].ki.wScan:=0;
  MyKeys[1].ki.dwFlags:=4+2;
  MyKeys[1].ki.time:=0;
  MyKeys[1].ki.dwExtraInfo:=0;
  SendInput(2, MyKeys[0], sizeof(tagInput));
end;

You can find more info on msdn

CloudyMarble
  • 36,908
  • 70
  • 97
  • 130
  • That code *presses* the caps-lock key. You might want to add another keyboard event to simulate the *release* of the key. – Rob Kennedy Feb 14 '11 at 06:12