Mirror

How to turn the CapsLock on and off (Views: 14)


Problem/Question/Abstract:

How to turn the CapsLock on and off

Answer:

procedure SetLockKey(vcode: Integer; down: Boolean);
begin
  if Odd(GetAsyncKeyState(vcode)) <> down then
  begin
    keybd_event(vcode, MapVirtualkey(vcode, 0), KEYEVENTF_EXTENDEDKEY, 0);
    keybd_event(vcode, MapVirtualkey(vcode, 0), KEYEVENTF_EXTENDEDKEY
      or KEYEVENTF_KEYUP, 0);
  end;
end;

Call by:

SetLockKey(VK_CAPITAL, True); {caps lock down}

<< Back to main page