jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Turning numlock on and off Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Turning numlock on and off" Watch "Turning numlock on and off" New topic

Turning numlock on and off

Adin Aronson

Joined: May 20, 2005
Posts: 7

Simple question here: How can I programmaticly turn numlock on and off

Joel McNary

Joined: Aug 20, 2001
Posts: 1824

I don't know of a way to programatically turn it on, but (depending on the type of program you're writing) you could listen for key pressed events on the VK_NUMPAD[0-9] keys. (See KeyEvent for more info). If you're listening for KEY_PRESSED events, it doesn't matter whether the NUMLOCK is on or not; pressing those ekys always generates the VK_NUMPADX events. Although this is not a fun-happy thing; I can think of a dozen things that would make this not work. (Your user could be on a laptop that doesn't have a numpad, the input takes the char value while you're listening for the actual key hit, etc.)

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
I'm pretty sure this is possible. I vaugely remember a short Java example that did waiting by cycling the NumLock, CapsLock, and ScrollLock lights on the keyboard. I think it was one of the SwingHack articles on java.net. I'll try and find it.


found it here
[ May 20, 2005: Message edited by: Steven Bell ]
Adin Aronson

Joined: May 20, 2005
Posts: 7
Thanks Steven, I'll keep looking too.

Joel, I'm looking to actually turn the num lock on, but thanks anyway.
Adin Aronson

Joined: May 20, 2005
Posts: 7
Well, I did a search for SwingHack and NumLock on Google and got to:
unfortunately, the setLockingKeyState command used there does not work on Linux (which is where i planned on using it).
I did come across a jvm call SableVM which had something about setLockingKeyState, so I will check it out.
I agree. Here's the link: http://aspose.com/file-tools
subject: Turning numlock on and off
It's not a secret anymore!