DIGIT-ARC read-only archive · snapshot: July 23, 2026

Javascript to detect number lock , on or off

12 posts · originally from https://geek.digit.in/community/threads/javascript-to-detect-number-lock-on-or-off.20670/

E
eureca_eureca Original post #1
Dec 19, 2005 at 6:15 PM
Please help me find a code for javascript which can detect whether number lock button is on or off..
E
Dec 20, 2005 at 5:58 PM
ghemant i couldnt ind that script there ..
G
ghemant #4
Dec 21, 2005 at 4:17 PM
NumLock on or Off

Hi,
please find the link for HOW TO CAPTURE A KEY STROKES USING JAVA SCRIPT , NOW I THINK YOU CAN DO THE TWEAK.

*www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2999&lngWId=2


:)
Regards
E
Dec 21, 2005 at 4:38 PM
ghemant that code will capture key codes, bu how to get true or false for the num lock , ie if its on or of ?
S
Dec 21, 2005 at 7:23 PM
Afaik, it is not possible to check status of numlock from javascript... The ability to detect keypress comes from usage of events, but this is a sytem status which I do not think is made available.

BTW, why do you want to do it? Perhaps an alternative method might be available. Or perhaps you can use a different scripting tool that can check the status such as VBScripts though not sure if they have ability to do it...

Arun
G
ghemant #7
Dec 22, 2005 at 9:45 AM
Num Lock Status

Hi,
its their in vb to identify / status , if num lock is on or not and its their in vb and java tooo , as if javascript is able to capture the keystrokes you have to do the tweak and its a possible thats what i feel.

:)
Regards
tuxfan
tuxfan #8
Dec 22, 2005 at 12:08 PM
Status of Num Lock, Caps Lock, Scroll Lock, etc. is stored in memory at location number 0x417. Now C lets you use pointers and access that memory location and with the value stored there you can find out the state.

VB is a totally different thing altogether. Although, there are no pointers, there are built-in functions/controls to do this.

You can't use pointers with Javascript (thankfully!!). So unless there is a built in library function to do this, its not possible. In 15-20 minutes I couldn't find any such library function from the Javascript 1.4 Reference that I have. :( So I doubt that its possible at least till Javascript 1.4

But don't lost heart, keep trying and let us all know if you find it :)
E
Dec 22, 2005 at 1:47 PM
i tried saearching for vbscript too , i couldnt find there too..
Thx ever one for the help ..
puja399
puja399 #10
Dec 23, 2005 at 10:53 PM
However, there is a workaround. U need to build a COM wrapper for a suitable API, viz, "GetAsyncKeyState" and use that object through ur vbs program. You have to distribute that COM object also with ur script file in case u need to run it somewhere else.
I
icecoolz #11
Dec 25, 2005 at 9:08 PM
well sounds like hellava lot of work just to find out if the Null lock is active or not. AFAIK there is no way to know in javascript if things such as Scroll lock, num lock and so on are active. And as for the C, java, VB which allows you to be able to detect these, remember javascript still works within the dimensions of your browser, where in the others they have access to the system and hence are not running in a "sandbox" environment.
puja399
puja399 #12
Dec 25, 2005 at 9:14 PM
Ya, u r right. U can't do it in javascript. It was my mistake that I misunderstood the problem and gave a solution for VBScript.