• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

key presses

 
Lawrence Buensalida
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to create a function that can catch the keys pressed on the keypad so that I can get their letter equivalent, using GameCanvas. How do I make such function?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the KeyListener class that is already there.

Mark
 
Koh Khai Huat
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
i would like to ask if there is really a keylistener class in the J2ME API??? because i dun seems to find it in the J2ME API.
for wat i know i only know that there is such class in J2SE but not J2ME.

so i would like to ask again how do i listen to a key pressed on GameCanvas?? i know it can be done iun Canvas but it dun seems to work in GameCanvas which is a direct subclass of Canvas.

thank you
 
Eduardo Marques
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to do 2 things:

1. In your constructor pass false so that GameCanvas does not suppress key events.

2. Define the keyPressed() or keyReleased() callback events.

Note that if you want to detect game keys only (which may or not be those in the numeric keypad) you should use GameCanvas.getKeyStates() and pass true in the GameCanvas constructor instead of handling assynchronous key events this way. It should be far more efficient.

[ August 22, 2005: Message edited by: Eduardo Marques ]
[ August 22, 2005: Message edited by: Eduardo Marques ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic