Link to home
Start Free TrialLog in
Avatar of TeChNiCh
TeChNiCh

asked on

Keyboard Lights

I wonder how i can get the "Keyboard Ligths"
(NUM LOCK/CAPS LOCK/SCREEN LOCK) to all be turned on...
ASKER CERTIFIED SOLUTION
Avatar of DragonSlayer
DragonSlayer
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sundayboys
sundayboys

function IsNumLockOn: boolean;
var KeyState: TKeyboardState;
begin
GetKeyboardState(KeyState);
Result := (KeyState[VK_NUMLOCK] and 1) = 1;
end;

procedure NumLockOn;
var KeyState: TKeyboardState;
begin
GetKeyboardState(KeyState);
KeyState[VK_NUMLOCK] := $01;
SetKeyboardState(KeyState);
end;

procedure NumLockOff;
var KeyState: TKeyboardState;
begin
GetKeyboardState(KeyState);
KeyState[VK_NUMLOCK] := $00;
SetKeyboardState(KeyState);
end;

// these tips can use with other keys ie. VK_CAPITAL, VK_SCROLL

SundayBoys,

From the Win32 API help file:

Because the SetKeyboardState function alters the input state of the calling thread and not the global input state of the system, an application cannot use SetKeyboardState to set the NUM LOCK, CAPS LOCK, or SCROLL LOCK indicator lights on the keyboard.


DragonSlayer.
DragpmSlayer?F
  try my code,it can change NUMLOCK lights.my OS is win98se.
  Don't  always trust Microsoft!
I think the code does not only sets the numlock light but also the numlock state!
The problem is that Windows now has a virtual system keyboard and you cannot fiddle with the keyboard controller anymore. It may be that your oly keyboard is USB which is not controlled by the keyboard controller.
We needed to control the LEDs (including the state) in win9x in our firm, too. We worked hard on that and finally found a method which works more or less reliable. But it works only in connection with our little keyboard driver.

We also tried the SetKeyboardState stuff, of course, but somehow it made problems. I don't remember exactly, what the problem was. I think, it was not reliable, on some keyboards it did work, on others it did not.

Regards, Madshi.
hi.
Something like this?


procedure TurnAllOn;
var
  keys: TKeyboardState;
begin
  GetKeyboardState( keys );
  keys[VK_NUMLOCK] := 1;  {Num Lock}
  keys[VK_CAPITAL] := 1;  {Caps Lock}
  keys[VK_SCROLL]  := 1;  {Scroll Lock}
  SetKeyboardState(keys);
end;

procedure TurnAllOff;
var
  keys: TKeyboardState;
begin
  GetKeyboardState( keys );
  keys[VK_NUMLOCK] := 0;  {Num Lock}
  keys[VK_CAPITAL] := 0;  {Caps Lock}
  keys[VK_SCROLL]  := 0;  {Scroll Lock}
  SetKeyboardState(keys);
end;


Dennis
Administrative Action - Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange