• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trouble with Toolkit.setLockingKeyState behavior

 
Brian McFarland
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I'm writing some code that needs to manipulate the NumLock key. I found some examples using the Toolkit class in java, specifically the get and setLockingKeyState methods, which let you find or set the status of the lock keys. These methods show odd behavior for me, however. This is a test snippet of my code, particularly the portion that manipulates the Numlock key:



I haven't been able to find an exact pattern while debugging through this code, but it seems that if my NumLock is turned on when I run the application, then the first line, which turns NumLock on does nothing, which is correct, and the next line will output true, also correct. The line to turn NumLock off will also toggle the key off correctly as well, the weird behavior begins when the next output line still outputs true. After the first test, I will run the code again, the second time through, the first statement still does nothing to the NumLock key, and the first output still outputs true. The third line will turn NumLock back on, despite being false, and the second output remains true. Basically over multiple tests, the third line will toggle NumLock to the opposite of its current state.

The reason I have been unable to find an exact pattern is that sometimes when I first turn my computer on, if NumLock begins in the off state, then the first line of this code will turn toggle the key on and off, like how the third line was, and then every output will show up as "false".

This behavior seems quite bizarre and I have found two threads mentioning this, but I haven't seen any solid answers to the questions. Has anyone encountered this problem before? Thank you very much in advance.

Brian
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This issue has shown up last year: http://www.coderanch.com/t/411292/Java-General-beginner/java/Turn-lights-off-with-Java
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic