Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

KeyListener

 
Alexander Walker
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found some things when using a KeyListener that seems strange to me.

1. There is a InputEvent.ALT_GRAPH_DOWN_MASK that can be used to check if the Alt Graph is down, however whenever I press the Alt Graph key, the keyPressed method is called twice, first with Ctrl as the modifier and then with Ctrl+Alt as modifiers. Seems to me like it simulates Ctrl+Alt being pressed. Why even have a InputEvent.ALT_GRAPH_DOWN_MASK if it's never used? Or is it meant to be used with somthing else? Or is there something else that is the reason?

2. When presseing the Alt key twice in a row, the second time the keyPressed event is never fired. On the third time the method will be called again.

3. When pressing the Alt key once and then pressing the Ctrl key, then the keyPressed event is never fired no matter how many times you press it, but if you then press ONCE on the Alt key and then press the Ctrl key it will fire.
Key sequence example: Alt, Ctrl, Ctrl, Ctrl, Alt, Ctrl, Ctrl. The key pressed event for presesing the Ctrl will only be fired the two last times Ctrl is pressed. This probablöy have sometinh to do with 2. Seems to be the same if you do it with Shift or Caps lock too.

4. If I press the Alt key once and then press a letter key, then the keyPressed is not fired, however it will be fired if you press the letter once more.
Key sequence example: Alt, B, B, B. The keyPressed event is only fired the last two times when pressing the letter key B. This probably have someting to do with 2.


That was those things that I found, I hope I made any sense. I'd like to know if other peaple are also having the same problem, or is it just someting I have?


Heres is my code that can be run to check these things.
 
Rob Camick
Ranch Hand
Posts: 2542
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Alt key is used to invoke the Windows System menu. Try "Alt" followed by the "Down arrow" key.

As a general rule you should be using Key Bindings and not listening for KeyEvents.
 
Alexander Walker
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:The Alt key is used to invoke the Windows System menu. Try "Alt" followed by the "Down arrow" key.

Thanks for the good answer. That answer question 2-4.

Rob Camick wrote:As a general rule you should be using Key Bindings and not listening for KeyEvents.

What is the reason that one should be using Key Bindings instead of a KeyListener?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic