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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Num-lock Question

Status
Not open for further replies.

ronnetp

Programmer
Apr 8, 2002
71
I have the following code to enable the Num-lock Key,
set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "{NUMLOCK}"

but I need it to be able to verify the state before,

if Num-lock key is active
dont change state
is Num-lock key is inactive
Activate Numlock key.
Any advice is well appreciated.

Thanks,
 
Hello ronnetp,

This is an utterly unrewarding little task to do with vbs. It is so unreliable. Not to mention a routine to check it first, even the sendkey by itself seems very unreliable to toggle the light on the keyboard. Do your experience convince you that the result being consistent?

To check the numlock state, one of the trick is to use the winword as a vehicle to do it for you.

Set objWord=CreateObject("Word.Application")
boolStat=objWord.NumLock
objWord.Quit
Set objWord=Nothing

Remember to quit the word by .Quit otherwise the silent process would build up in number and bloat your box by repetitive testing.

Warning: This is very unreliable. If you go to test it, you know what I mean. It is as unreliable as the SendKeys, no more no less.

So, both little tasks, I am not enthusiastic about.

regards - tsuji
 
Thanks, tsuji

For sharing, another problem besides not been reliable
is that I have workstations that dont have Word Installed.

I have not found a way of doing this!!!
 
Sadly, the most reliable way of doing this is with the SetKeyState API call. Unfortunately you cannot make direct API calls with VBScript
 
I can use other way, for me it does not have to be
vbscript, I just wanted to make something without
needing to compile.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top