Polling number pad states with GameCanvas?

Hey guys, it’s been a while since I posted on the forum. Hope everyone’s doing well!

I have a need for polling number pad key states with a GameCanvas. I know I can use keyPressed() and such on a normal Canvas, and how to poll the directional and fire buttons on a GameCanvas, but I’m not sure how to poll the number keys with a GameCanvas. Are there constants defined for the number key state? If not, is there a workaround?

Thanks for any help!

Read the javadocs, in particular the Canvas class.

KEY_NUM0-KEY_NUM9, KEY_STAR, KEY_POUND.

They’re basically the ascii standard key codes.

Hey Abuse, thank you for your reply. I’m not sure I explained what I was looking for well enough, however.

I checked out the Canvas javadoc again, but the info I’m looking for isn’t there. I’m not really looking to remap direction keys to number keys, but instead polling the number keys independently (so I could move with the directional buttons, and do some other stuff with a few of the number keys). I already know the keycodes for the number pad, but don’t know any constants that say whether they are being pressed, and thus how to see if they’re being pressed in a GameCanvas.

Of course, the idea of mapping the A/B/C/D keys to the number pad keys crossed my mind… but, unfortunately, the explanation in the javadoc is (as usual) lacking. I have no clue how to remap the keys based on the information within that document. Still, in the ideal case, I would like to be able to poll the number keys themselves.

Please bear with me here, I only started doing this stuff a week-and-a-half ago. :stuck_out_tongue:

So you are using GameCanvas.getKeyStates() ?

Don’t - its a useless mechanism for discovering whether a key is pressed or not.

Simply handle your key input in exactly the same way you would in a J2SE app.
In keyPressed, set a flag for the associated key, in keyReleased, clear the flag.
The keycodes for the numeric keypad are defined - the keycodes for the d-pad are not, and will vary from handset to handset.
You have to discover their values through experimentation & research.

Obviously it gets a little more complicated than that - when you have handsets that don’t always deliver keyReleased events after the associated keyPressed event - however, you can worry about that when you get to it.

Excellent! Thank you again, Abuse. I was using getKeyStates() the whole time. I also had the GameCanvas suppress key events, so I turned that off. After a minute or two of tinkering, I got something working. I had tried to use keyPressed() before in a GameCanvas, but didn’t realize I had key event suppression flagged. Thus, I thought that keyPressed() and the associated routines weren’t available. I gotta learn to pay attention! :wink: