PocketMatrix forums

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

Key Mappings

I just wrote a key-remapper for Dr. Pocket, but I ran into something funky.

On my Dell Axim, when Button A is pressed, it calls the ButtonDown function twice (using PocketFrog). The first call sends a button value of 91, and the second sends a button value of 193 (which is the unique value). That same 91 is also sent for buttons B, C and Start, in addition to their unique values (194, 195, 196).

And the same behavior exists for the D-Pad. Except instead of sending a button value of 91, it sends 132 in addition to the unique values (37, 38, 39, 40).

So, does anyone else see this behavior? If you didn't understand what I said, ButtonDown is always being called twice with the following values:
Button A - 91 and 193
Button B - 91 and 194
Button C - 91 and 195
Button Start - 91 and 196
D-Pad Left - 132 and 37
D-Pad Up - 132 and 38
D-Pad Right - 132 and 39
D-Pad Down - 132 and 40

I'm curious if this is unique to the Axim, or is it standard across PPCs.

Thanks,
-John
I recall seeing something similar with my old iPaq 3670. I don't remember what the actual values were, but I do remember that two buttondown events were being sent with each button press.
Hi Presto,

I was wondering if you found a solution or an explanation for the double key you get on the PocketPC.

My device is an iPaq 3850 and I'm getting the same thing as you noted in your message back in april, except for the start button which returns 134 followed by 13.

I have taken care of code 132 in my keydown handler, but I don't feel very good about this. Especially since I will have a way for people to remap the keys themselves.

Thanks for any info.

--Eric
I simply filter out 91 and 132...
I don't see any other solution at this point since this stuff seems to be completely undocumented.
Ok, thanks.

And check out that 134/13 pair, which I'm getting when I press the start button. 134 is my normal code. Maybe 13 is added so that it's compatible with a Return keypress?

--Eric
warmi wrote:
I simply filter out 91 and 132...
I don't see any other solution at this point since this stuff seems to be completely undocumented.


I do the same thing.

Also, the different value for Start matches with what I've seen (using an Axim and E350). Different PPC vendors have different keycodes, which can get quite frustrating. I'd really like to see a compiled list of the different PPCs and their key values.

I guess it's just a good practice to give the users the ability to remap their keys.

-John
Hm, this is interesting.

For my game, I was thinking of providing user key mapping (via GUI and config file), and also trying to come up with decent default key mappings for various devices.

If some devices return weird key presses, this makes it harder to write a key mapper.

What about key up events? Are they duplicated also? If not, I'd suggest listening for key up events in your key mapper.
Yes, key ups also send the second key, which I call the shadow key.

My best explanation would be that it's a keypress meant to emulate another function that some application might require.

Note that if you are using GapiDraw, it will correctly retrieve the A-B-C-START and D-Pad keys for you, but the other one are non-standard.

--Eric
OK, so let me get this straight.

The user has effectively said, I want to remap the button for action X.

Now the program says, press the button you wish for action X, and waits for button press events.

The user presses a button, and on some devices, you get these events:

buttonDown shadow code
buttonDown intended code
buttonUp shadow code
buttonUp intended code

Is that the correct order?

So in this case, the problem is to find the intended code. Is it always the second press? How about this heuristic: when mapping a key, if you get two button down events before a button up event, use the second as the intended code.

If some devices only report one down event (no shadow codes), this won't handle the case where the user presses two buttons simultaneously, but if they do that while mapping buttons, it is their own fault and they can remap it again when they discover they got the wrong result.

Do all devices report shadow codes, or only some?

If the shadow code is not always first, we have more complicated problems. We can at least use the fact that several button presses generate the same shadow code, so if we can detect that shadow codes are indeed occuring, we can compare multiple button presses to determine which is the shadow code.
Nope, it's not always the second press.

On my Axim, it sends them in numerical order. So for a direction, I get the direction code (37-40) and then 91. For the other buttons, I get 132 and then the button value (193-196).

I'm not sure if anyone's found a perfect solution to this. I think right now it's best to filter out 91 and 132, though the earlier comment about the 134/13 values for the Start button is quite bothersome.

I'm pretty sure all of the devices have shadow codes though. Might be worth taking a tiny app into Best Buy and finding out as many codes for the different devices as possible.

-John
I would not want to filter out hardcoded codes.

I would rather heuristically determine which are the shadow codes, and also allow for them not to be present, in case other devices have different shadow codes or no codes.

In the worst case, you could have the user pre-configure the keymapper by pressing all buttons on the device. Then, I presume you can determine which are the shadow codes, by looking for duplicates.
I know this thread is old, but it's still relevant and unsolved (at least I haven't found the solution).

There appears to be a pattern (this will require testing):

D-Pad keys have values of < 100.
Normal keys have values of > 100.

Shadow D-Pad keys have values of > 100.
Shadow normal keys have values of < 100.

Please test your devices to make sure all regular keys map to a value > 100 and all d-pad keys map to values < 100. If this ends up to be true, then we can create a filter that works for all devices.

I have the Axim x50v and it appears to be the case on my device. Looking at previous posts, this is also true for all other Axims as well.
Okay, after a large amount of research I've come across this (special thanks to StephC):

http://www.cewindows.net/developer/pocketpcbuttons.htm

I believe the shadow keys can be filtered out give this information. On each keydown or keyup, test for 0xc1 through 0xc6, and of course the four directions on the d-pad. If the keycode is none of those, simply ignore it. This should solve shadow key issues with all devices.

Also, you'll notice just about every device defaults to 0xc1 through 0xc4 for the 4 buttons (left to right). This should give a good setup for default keys that will please most users out there.
Dan, thanks alot for posting this follow up. It really saved my hide!

--Eric