• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

KeyListener

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Good night. Drive safely. Here's a tiny ad for the road:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic