Sunday, May 3, 2009

Whether the NumLock Key is On or Off

have decided to made this thread to all those who are Newbie and want to make the Computer System more User Friendly.
I had also face the same problem when I was New to the Computer World, so I am thinking that, New user should not face the same problem.

I am posting each Tips and Tweaks in each of my reply.

How Can Tell Whether the NumLock Key is On or Off?

1.you can’t use a technology like WMI, Windows Script Host, or the Shell object to determine whether or not the NumLock key is on. And yet, you can use Microsoft Word to carry out that task:

Quote:Set objWord = CreateObject("Word.Application")
Wscript.Echo "NumLock key is on: " & objWord.NumLock
objWord.Quit 

Granted, it’s a little weird; on the bright side, it’s also a very simple little script. To begin with, we create an instance of the Word.Application object. Notice, however, that – unlike most of our Microsoft Office scripts – we don’t set the Visible property to True; that’s because there’s no reason to make Word visible. That’s due, at least in part, to the fact we need Word for only one thing: to check the value of the NumLock property. To determine whether or not the NumLock key is on we only have to execute this line of code:

Quote:Wscript.Echo "Numlock key is on: " & objWord.NumLock 

After that we simply call the Quit method and terminate our instance of Word.

Weird, but effective.

Incidentally, you can also use this same basic approach to determine whether or not the CapsLock key is on; the only difference is that you echo back the value of the CapsLock property:

Quote:Set objWord = CreateObject("Word.Application")
Wscript.Echo "CapsLock key is on: " & objWord.CapsLock
objWord.Quit 

Now, admittedly, you probably don’t really need a script to tell whether the NumLock key (or even the CapsLock key) on your local computer is on or off; a quick glance at the keyboard will probably suffice. But that’s OK: this script can also be used to determine whether the NumLock (or CapsLock) key on a remote computer is on or off. All you have to do is pass the name of the remote computer as the second parameter to the CreateObject method. For example, this script determines the status of the NumLock key on the remote computer atl-fs-01:

Quote:Set objWord = CreateObject("Word.Application", "atl-fs-01")
Wscript.Echo "NumLock key is on: " & objWord.NumLock
objWord.Quit 

The one thing that this script can’t do is change the status of the NumLock key: it can tell you that the NumLock key is on but it can’t turn it off for you. (That’s because the NumLock property is read-only.) About the only way we know to toggle the NumLock key on and off is to use the SendKeys method:

Quote:Set objShell = CreateObject("WScript.Shell")
objShell.SendKeys "{NUMLOCK}" 

This works, although it won’t work on remote computers (SendKeys works on only the local machine). However, this might be useful in a logon script: in such a script you could check the status of the NumLock key and then, if needed, turn it on or off.

No comments:

Post a Comment