PDA

View Full Version : Can I check numeric lock state in any way?



Mastiff
October 28th, 2004, 08:39 AM
I would like to check if numlock is activated or deactivated. Is it possible?

Treetop
October 28th, 2004, 11:47 AM
Just thinking off the top of my head here...

Create a command that sets the registry when the numlock key is pressed. Then you could poll the registry to see the status.

I wonder if the numlock's status is already saved in the registry somewhere? That would be ideal.

Good Luck,
Treetop

Edit: I threw this together just to test... Seems to work okay, but I cant help but feel there is a better way :wink: Should be relatively easy to do in LUA, but I havent researched it.

Jlee
October 28th, 2004, 01:14 PM
Is this any help?
http://support.microsoft.com/?kbid=314879

Promixis
October 28th, 2004, 01:26 PM
There is a way to do this. Don't have time right now :(

Mastiff
October 28th, 2004, 01:33 PM
Treetop, thanks, but that doesn't work when the state is changed during bootup or resume from hibernation.

J.Lee, thanks, but it's Win2K3, not XP, I'm afraid. I haven't tested the script yet, but it says that it's only for XP.

Mike, thanks. I can wait. This is more of a security measure to make sure my kids don't mess up. If anything kan be messed up, they will manage it, which is why I like to have my setups 100 % foolproof.

I would like it to be able to check the status, not only set it.

VaioUserChris
October 28th, 2004, 08:35 PM
Tor,

One way to do it is to use the KeyboardEX plugin. That plugin can't see the state of the num lock key directly, but it can see its effect. If you press a 7, and num lock is activated (i.e. you're typing a 7 as far as the computer is concerned), it will send an EventString of "6700000" but if num lock is off (i.e. you're sending the HOME command), that same key sends an EventString of "2400000".

This is of course true for each of the number keys and the period on the number pad.

And, KeyboardEX can tell the difference between pressing a 7 on the num pad (EventString of "6700000") and the 7 below the function keys (EventString of "3700000").

So if you don't mind watching for keystrokes on the num pad, this is an easy way to determine if the num lock is active.

Here's a script to watch for KeyboardEX events (i.e. keystrokes) using the LUAEvents plugin.
AddEventHandlerName(124, "", "ExampleEvent")

function ExampleEvent()
print(EventString)
end
Chris

Mastiff
October 29th, 2004, 01:29 AM
Thanks, Chris! That one I should be able to use! I'll just put it in front of every command and then fire a "activate numlock" if the key is wrong. :D

VaioUserChris
October 29th, 2004, 09:39 AM
Tor,
Glad that helps. I had recorded the EventStrings for each of these keys in the past so here they are. You're right, you could just watch for any of the non-numeric codes and send num lock if it sees one of them.


Num Lock Active
Key EventString
7 6700000
8 6800000
9 6900000
4 6400000
5 6500000
6 6600000
1 6100000
2 6200000
3 6300000
0 6000000
. 6E00000


Num Lock Not Active
Key EventString
Home 2400000
Up 2600000
Pg Up 2100000
Left 2500000
Center(5) 0C00000
Right 2700000
End 2300000
Down 2800000
Pg Dn 2200000
Ins 2D00000
Del 2E00000

Chris

VaioUserChris
October 29th, 2004, 09:51 AM
Tor,

What the heck, I had a few minitues so I wrote the script for you. Here you go -- all you need to do is add the command to trigger your num lock activate event.

Chris

teststring = {"2400000", "2600000", "2100000", "2500000", "0C00000", "2700000",
"2300000", "2800000", "2200000", "2D00000", "2E00000"}

AddEventHandlerName(124, "", "NumLockTest")

function NumLockTest()
for i = 1,11 do
if EventString == teststring[i] then
print ("num lock not active") -- place your event to trigger num lock here
break
end
end
end

Mastiff
October 29th, 2004, 10:08 AM
Thank youy very much! :D