Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Keyboard Lights

Posted on 2001-08-10
11
Medium Priority
?
586 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 800 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
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!

 
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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

610 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