aspose file tools*
The moose likes Beginning Java and the fly likes Trouble with Toolkit.setLockingKeyState behavior Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trouble with Toolkit.setLockingKeyState behavior" Watch "Trouble with Toolkit.setLockingKeyState behavior" New topic
Author

Trouble with Toolkit.setLockingKeyState behavior

Brian McFarland
Greenhorn

Joined: Oct 10, 2008
Posts: 8
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

Joined: Oct 27, 2005
Posts: 19783
    
  20

This issue has shown up last year: http://www.coderanch.com/t/411292/Java-General-beginner/java/Turn-lights-off-with-Java


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trouble with Toolkit.setLockingKeyState behavior