Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Aren't Listeners very strange creatures?

 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Playing around with listeners here I've noticed that when you're checking for modifiers, the listener still gets invoked twice.
Typing ALT-6 for example :
The listener gets modifier ALT and key ALT the first time.
The listener gets modifier ALT and key 6 the second time.
I suppose this makes sense but it seems messy when you're doing one check for if ALT-6 has been pressed by checking for the modifier and the code. In effect you check the first time, where you don't pass because the code is set to ALT. The second time you do pass because the code is set to 6.
Any comments?
Paul
 
Angela Lamb
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How did you write your listener? I tested this with a simple KeyAdapter and the listener was only invoked once.
 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe it's because you're using KeyTyped. I haven't ventured too far down that road because I was under the impression there was some bug with using the KeyTyped method rather than the KeyPressed method.
Paul
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!