• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

key presses

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at the KeyListener class that is already there.

Mark
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic