Skip to main content
Inspiring
December 16, 2008
Answered

Recognizing key presses without a mouse click

  • December 16, 2008
  • 1 reply
  • 397 views
My program beings with a frame with a "play" button on it. Once he "play" button is clicked the user is taken to the second frame to play a game. Control for the game is done via key presses. The control works well; I'm able to move the sprites and so forth. However, my problem is after the user clicks "play" and is taken to the second frame the game will not recognize key presses until the user has clicked the applet again. How do I get the game to recognize key presses automatically after the user has clicked "play"?

Here is the code I use in the second frame to listen for key presses:

This topic has been closed for replies.
Correct answer Ned Murphy
Try using stage.focus = this; up top. I haven't done this myself at any time, but it might be a solution.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
December 16, 2008
Try using stage.focus = this; up top. I haven't done this myself at any time, but it might be a solution.
60DayAuthor
Inspiring
December 16, 2008
Thanks, it worked perfectly!