Solved

Keyboard Lights

Posted on 2001-08-10
11
567 Views
Last Modified: 2010-04-06
I wonder how i can get the "Keyboard Ligths"
(NUM LOCK/CAPS LOCK/SCREEN LOCK) to all be turned on...
0
Comment
Question by:TeChNiCh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 14

Accepted Solution

by:
DragonSlayer earned 200 total points
ID: 6374690
procedure ToggleKey(VirtKey: Integer; SetOn: Boolean);
var
  IsToggledOn: Boolean;
begin
  IsToggledOn := (GetKeyState(VirtKey) and 1) = 1;
  if IsToggledOn <> SetOn then
  begin
    keybd_event(VirtKey, 0, 0, 0);
    keybd_event(VirtKey, 0, KEYEVENTF_KEYUP, 0);
  end;
end;


The above procedure will check if a key is toggled on/off.

To set CAPS LOCK to ON:

ToggleKey(VK_CAPITAL, True);
and to set it to OFF again:
ToggleKey(VK_CAPITAL, False);

NUM LOCK's virtual key is VK_NUMLOCK
SCROLL LOCK's virtual key is VK_SCROLL



DragonSlayer.
0
 
LVL 1

Expert Comment

by:sundayboys
ID: 6374729
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

0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 6374905
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:sundayboys
ID: 6374959
DragpmSlayer?F
  try my code,it can change NUMLOCK lights.my OS is win98se.
  Don't  always trust Microsoft!
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 6374993
:)
0
 
LVL 1

Expert Comment

by:sundayboys
ID: 6375071
:-)
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6375078
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.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6375230
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.
0
 
LVL 1

Expert Comment

by:Dennis9
ID: 6377162
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
0
 

Expert Comment

by:SpideyMod
ID: 8145016
Administrative Action - Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question