PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Help on Pocket PC button mapping code?

Hi There,

I want to let the users configure Pocket PC button/keys for FIRE, MOVEMENTS etc.

How can I capture button pressed or implement this?

Thanks.
Have a list of "actions" that the user can map on the screen... Instruct them to click on one (stylus usually, but doesn't have to be). When they do, whatever the next dwKey in keyDown (or up) you receive is what you map to that action. Not really much more to it than that.
Thanks Fz: But how do I implement this? Is it under keydown()? How do I get the button value?
You can do it under keyDown or keyUp, shouldn't really matter. I'd do keyDown just because it'll seem a bit more responsive to the user.

The button value is passed in as DWORD dwKey. You simply store the value of dwKey, in the registry perhaps, or a config file, whatever.

Then, in the code that handles key events for your actual game, you just do something like:

DWORD fireKey = getKeyFromRegistry(1);
if (dwKey == fireKey) { // Do fire }

getKeyFromRegistry is your function that returns the value you saved from the user's input, in this case it knows that a value of 1 means "get the value that was stored to represent the fire button". Obviously you wouldn't do this each loop, just once at the beginning of your program, but you get the point.

Does that all make sense, or did I blabber a bit too much? :)
FZ: It's clear to me now:-) Many thanks. Honestly, I dont have the idea on how to start coding this feature. Now I can include this maybe in a day or two. And you can see this in action soon. Cheers.


- others developers need this so this will be a big help too for them -
I haven't done this yet, but will eventually. I do have a suggestion however.

Approach this as two related, but separate problems.

The first problem is to provide configurable keys. Do this by reading in the key value for a particular action from a file (or whereever you store it) and use that key value for that action.

The second problem is to provide a nice interface for the user to configure those key values. This is the part where the user selects an action, then clicks the actual key they want to use for that action, and you get that key value and store it in your file (or whereever).

But remember that the nice interface is independent of the actual mechanism. Get the configurable keys working first, then worry about the interface later.
Should non GAPI exposed buttons be considered fair game for mapping?
mlepage, the approach you state pretty much applies for anything in programming that has a GUI related to it :) One should, I believe, always get the underlying code working and then worry about putting a nice interface over it. I guess unless the interface is the key component of the problem anyway. In this case your right, the primary concern is the code to provide the functionality. Indeed, if you write it decently, you'll be able to reuse the code in every project you use going forward and you can just "skin" it, so to speak.

Starfury, If it's non-GAPI exposed, I don't think you'll get notification in any of the key event handlers anyway, so it's a moot point (I presume we're still talking GD here, but it probably applies for PF or any other library).

The nice thing about mapping keys like this is that you as a developer don't have to worry about device configurations. As long as the GAPI implementation registers a keypress (and GD is set up to recieve it, if it has to do anything special at all), then it's fair game for mapping. Certainly, I think people will appreciate you allowing any key to map to any function, especially if manufacturers start creating physically funky devices. You never know what a person will find most comfortable in terms of button layout.
Actually , having non-GAPI exposed keys available to user is more than just a "nice to have" feature.
There are all kinds of devices out there, I remember someone with PPC Phone which had all GAPI-exposed buttons located at the top of device and, naturally , he wanted to re-map the default setting for ZRaid to use device specific keys instead (which were located in a much more convenient location on the device ) - stuff like that ...
I can think of other interfaces for mapping buttons. You could do it on screen, by entering the code manually. That's not much different than editing the file though.

You could have a screen display of actions and buttons, and drag/drop the actions to the buttons.

Or you could use the microphone and whistle in tones to represent the buttons. Not very practical. :-)

But all this should be possible on top of the general, configurable code.
I found that it was a must to provide the user with the ability to map their own keys for my game Jack the Uni-Psychle. After testing it on many pocket PC devices, the GAPI defined buttons were not always the 8 keys on the front of the device.. in some instances they were the record button on the side and in at least one case, one of the GAPI keys wasnt mapped to any key on the actual device. Since I need to use all 8 keys I just created a simple interface for them to map their own controls and it worked out great. When you do provide your own mapping there is a keycode you have to ignore, since all buttons throw that keycode in addition to their actual code. I think it was keycode 91 but I dont remember off the top of my head right now. But using a simple if (keycode == 91) return; fixes it and I had no problems out of all the devices I tested plus saw no problems from anyone who bought the game.

-Tim aka Spock
www.discordstudios.com