It's not a secret anymore!*
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
Author

Turning numlock on and off

Adin Aronson
Greenhorn

Joined: May 20, 2005
Posts: 7
Hi,

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

Thanks
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

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.

[Edit:]

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

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
Greenhorn

Joined: May 20, 2005
Posts: 7
Well, I did a search for SwingHack and NumLock on Google and got to:
http://weblogs.java.net/blog/joshy/archive/2003/08/swinghack_keybo.html
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.
 
wood burning stoves
 
subject: Turning numlock on and off
 
Similar Threads
CAPSLOCK and NUMLOCK Status
IntelliJ IDEA arrow navigation does not work with numeric keypad arrow keys
Trouble with Toolkit.setLockingKeyState behavior
CPAS LOCK ,NUMLOCK
Turn lights on and off with Java