Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Key presses one by one in JAVA Swing (only in Frame)  RSS feed

 
Venkatanathan Swaminathan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a cricket game in JAVA in an auditory only mode. I am in need of a code that would help me take key presses one by one such that combination of keys would make different kinds of bowling and the spin levels.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Store the different keys in a Set<Integer> or something similar when they are pressed, then remove them again if the keys are released again. Query the Set<Integer> to see which keys are currently being pressed.
 
Venkatanathan Swaminathan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that would be the case when a certain key is kept pressed down, but what is the case for example: I want to press a key like d for leg spin and the sound would start representing that of the bowler running and after 3 seconds I would take the direction from the direction key. But when the first key is released according to you wont my array be void of the first key as it has been released.
how do i deal with this ?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!