Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (500)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Polling number pad states with GameCanvas?  (Read 2589 times)
0 Members and 1 Guest are viewing this topic.
Offline theraje

Senior Newbie




If you're thinking what I'm thinking, get help.


« Posted 2006-10-08 14:32:41 »

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!

They say all great artists are insane. I'm not saying I'm a great artist, but I'm certain I have what it takes.
Offline Abuse

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #1 - Posted 2006-10-08 17:50:41 »

Read the javadocs, in particular the Canvas class.

KEY_NUM0-KEY_NUM9, KEY_STAR, KEY_POUND.

They're basically the ascii standard key codes.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline theraje

Senior Newbie




If you're thinking what I'm thinking, get help.


« Reply #2 - Posted 2006-10-08 20:02:03 »

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. Tongue

They say all great artists are insane. I'm not saying I'm a great artist, but I'm certain I have what it takes.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Abuse

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #3 - Posted 2006-10-08 21:33:53 »

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.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline theraje

Senior Newbie




If you're thinking what I'm thinking, get help.


« Reply #4 - Posted 2006-10-09 06:39:29 »

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

They say all great artists are insane. I'm not saying I'm a great artist, but I'm certain I have what it takes.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (51 views)
2014-04-15 18:08:23

BurntPizza (47 views)
2014-04-15 03:46:01

UprightPath (63 views)
2014-04-14 17:39:50

UprightPath (45 views)
2014-04-14 17:35:47

Porlus (62 views)
2014-04-14 15:48:38

tom_mai78101 (86 views)
2014-04-10 04:04:31

BurntPizza (144 views)
2014-04-08 23:06:04

tom_mai78101 (243 views)
2014-04-05 13:34:39

trollwarrior1 (202 views)
2014-04-04 12:06:45

CJLetsGame (209 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!