Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Numlock

Status
Not open for further replies.

Raven078

Programmer
Jan 14, 2003
22
NL
I want to disable the Numlock key with a delphi application. I have tried the keyboardstate statements, but I can't get it to work. Does anyone know a way to do this or how to use the keyboardstate things?
 
An example for switching Caps Lock is:

procedure TForm1.Button1Click(Sender: TObject);
var KeyState: TKeyBoardState;
begin
GetKeyboardState(KeyState);
if KeyState [VK_CAPITAL] = 0 then
begin
KeyState [VK_CAPITAL] := 1; label1.Caption:= '1' end
else begin KeyState [VK_CAPITAL] := 0; label1.Caption :='0'; end;
SetKeyboardState(KeyState);
end;


It should be the same for Num Lock using VK_NUMLOCK, according to my documentation, but it doesn't work.

The above code will work for Caps Lock, but doesn't activate the CapsLock LED on the keyboard. Maybe there is some hardware related issue for the Numlock?

Steven van Els
SAvanEls@cq-link.sr
 
It should be the same for Num Lock using VK_NUMLOCK, according to my documentation, but it doesn't work.

I have tried that already, but I have the same problem. I also found a component "keyled" which (re)sets num-, caps- & scroll-lock, but then my application resets numlock only when my application is the active window. Also when the mousecursor is on top of my application it switches numlock on and off like windows is switching between multiple running applications.

Maybe there is a way to solve the problem above, but I rather code everything myself.

Thanks anyway. [thumbsup2]
 
It works when you use:

if GetKeyState(VK_NumLock) <> 0 then //numlock not off??
begin
//press numlock
keybd_event(VK_NumLock, $45, KEYEVENTF_EXTENDEDKEY, 0);
//release numlock
keybd_event(VK_NumLock, $45, KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP, 0);
end;
 
hi,

I needed an app to switch Numlock on and I used this:

keybd_event(VK_NUMLOCK, MapVirtualKey(VK_NUMLOCK, 0), 0, 0);


and it worked for my (Delphi 5, command line app)

Griffe
 
Hi Raven078,

The problem is that Windows distingueshes( I dunno why )
turning the NumLock light on and actually pressing the
NumLock key.

When looking for the answer please bear this in mind.

Cheers,

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top