• Post Reply Bookmark Topic Watch Topic
  • New Topic

how would I go about reading more than one key at a time?  RSS feed

 
Noah Faust
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can read one key at a time just fine with the keyPressed function, but how would I read multiple keys at once?
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should probably ask this question in the Swing forum.
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't read multiple keys at a time, since you only get one key per event. What you can do is store the keys that have been pressed:
Of course, if you only want to monitor a few keys (like cursor keys) a few booleans would suffice. Or, for mutual exclusive buttons, ints. For instance, for controlling movement:
This way, a left and right pressed together will keep horizontal at 0. Releasing left will increase horizontal to 1, which is correct since right is still pressed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!