Solved

Keyboard Lights

Posted on 2001-08-10
11
561 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
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
 
LVL 5

Expert Comment

by:Netminder
ID: 7872453
0
 

Expert Comment

by:SpideyMod
ID: 8145016
Administrative Action - Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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