Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Turning numlock on and off

 
Adin Aronson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

Thanks
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Steven, I'll keep looking too.

Joel, I'm looking to actually turn the num lock on, but thanks anyway.
 
Adin Aronson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic