PocketMatrix forums

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

Possibly silly question about keylist...

Johan, anyone else... is it possible, and if so how, to get access to keylist OUTSIDE a key message handler?

What I'm trying to do is create my own class-level variable, DWORD vkAction, and assign it the value of keylist.vkA, but I need to do this in InitInstance().

Maybe it's just late and my brain's shut off for the night, but I don't see how I can do that. TIA!
If you're trying to do what I think you are (which would be to check if a certain key/button is pressed outside of the input events) you could try using GetAsyncKeyState( vk_code ). Using the Hiword of the return value will give you your answer as to what is being pressed (or released).

If you needed a valid GDKEYLIST structure outside of the event handlers, my guess is that you would have to manually fill it in yourself and with using GetAsyncKeyState.

However, you may be doing something else other than what I think you're doing - in which case my reply may not even relevant.
That was a good guess Layre5150! Actually though, I was writing a key mapping screen in my game. What I've done is I have six DWORD variables in my game class, vkUp, vkDown, vkLeft, vkRight, vmCommand and vkAction. In my key mapping button event handler, I'm basically doing:

// If we're assigning the vkCommand button...
if (dwKey == keylist.vkA) { vkCommand = keylist.vkA; }
// ... and so on

So, what I wanted to do was have default values in those six variables that echo what's in keylist, since chances are they won't even need to be remapped most of the time anyway. Doing it in InitInstance() seemed to make the most sense.

I'd still like to know the answer to my question, but it's actually no longer relevant since something dawned on me in the shower (where most of my good ideas hit me!)... instead of checking for the various members of keylist in my handler and assigning as appropriate, all I really need to do is:

// If we're assigning the vkCommand button...
vkCommand = dwKey;
// If we're assigning the vkAction button...
vkAction = dwKey;
// ... and so on

That way, I can handle buttons that aren't registered in keylist too (I assume they would still come through Johan? I'm thinking maybe the fourth button on an Axim, which I would guess would be vkD if it was a member of the structure, but since it isn't, I'd still get some values passed to KeyUp, right?).


EDIT: Please ignore the part where I say this is no longer relevant! It still may be, so I still need an answer. I'm thinking about the whole "phantom" button press thing... I presume that the first value passed in would NOT be one of the values in keylist, therefore it's probably correct to still check against what's in the structure, in which case I'll still need to be able to set default. I'm probably just confusing things here, so ignore it all and just focus on the underlying question: How can I get the value of the vkA member in keylist (for example), outside of a KeyDown handler method, preferably in InitInstance()?
Frank, I'm going to write a key mapper for my game in a few days, and I intend to solve this phantom key press issue once and for all. I'll let you know if I learn anything.
Good luck, I look forward to anything you find out. I know many people have looked into this and dealt with it in various ways, but none seem to be generic and across-the-board. I hope you figure something out :)
That way, I can handle buttons that aren't registered in keylist too (I assume they would still come through Johan?


Yep, that's how it works.. :)
Ok, good. Johan, what about my original question? Is it possible to get at the values in keylist outside an event handler?
With GapiDraw you can only request the keylist after the display and input has been opened. This is due to the fact that the buttons up/down/left/right are mapped to the current display alignment.. So you could probably not do it in initinstance. But you could however simply include gx.h or copy the key values from that and set those values in InitInstance, and then set the values again in CreateSurfaces or whatever when the display is initialized...
Why not simply do the key assignment from within a setup screen after the game has initialized? You could easily store the settings in the registry, then restore them every time the application is started.
Johan: That makes perfect sense... I don't have to do it in InitInstance, I can do it in a number of places after that... The real question though is can I get access to the keylist structure outside a KeyDown or KeyUp method? If so, how? It didn't look like it was accessible from anywhere... is it named something different internally that I can access?

G.R.: That's not a terrible idea... I could chain directly to my options screen on the first run where my store file wasn't found (that's where I, uhh... STORE everything!, including key mappings)... but I'm not sure I'd like an app that did one thing one time and worked another every other time... I'd still prefer to have some default values that will work initially.

I can do as Johan suggested and get the values from gx.h, but that feels a little like working against GD. I'd much rather get it from the keylist structure, that way if GD ever does anything in between my app and GAPI (i.e., maybe some mapping thing), then I'd still work.
fzammetti wrote:... but I'm not sure I'd like an app that did one thing one time and worked another every other time... I'd still prefer to have some default values that will work initially.


Well, you do have default values that will work initially - the settings that come up the very first time you run the game. After the user sets their preferences and they get saved, you simply restore them at startup every time.
Well... let me think this through a bit... I have some variables that I will use in all my key event handlers, so for instance I'll do:

if (dwKey == myVKAction) { // ... And so on...

where myVKAction was previously assigned one of the values from keylist during mapping. So, maybe the variable myVKAction has the value of keylist.vkUp for the sake of argument because the user wanted the joypad up movement to be the Action key for some bizarre reason.

I suppose it's true that in the first key handler entered, which would be my main menu because it's the first I can be 100% sure gets hit, the into and title screens I can't be completely sure will fire if the user lets them play out), I could check if I've loaded values yet, and if not I can assign them at that point because of course I have access to the keylist struct at that point. That should work fine and is no big deal to implement. That's not a bad idea G.R., and I'll do that in the absence of doing it the way I'd prefer. Since my intro and title screens will stop on any button hit, there's no concern about what's mapped to what at that point.

I would still like to know the answer though, because while I think this will work perfectly fine, it's not really the logical place for this code to be in my mind. It might be the only choice, but without the answer to my question I can't be sure.

In any case, thanks for the thought, I think it will solve my problem one way or another!
CGapiApplication has m_input which has method GetKeyList. Is that what you want?
fzammetti wrote:In any case, thanks for the thought, I think it will solve my problem one way or another!


In my mind, nothing can be done by the user until you've created the display anyways. So, by that time you will already have the default keymapping available to you.
Thanks mlepage! That's exactly what I needed. I missed that in my documentation cruising, but I think that's precisely what I was looking for. I'll just have to be careful to only use that after input has been initialized, but I'm almost certain that's the answer. Thank you!
Just wanted to let you guys know it worked out exactly as expected, key mapping in my game now works perfectly (aside from writing out to a file and making sure there's no device-specific issue, the file writing I'll add tomorrow, no big deal). Thanks again to mlepage for pointing that method out to me, it was what I needed!
I was under the impression that "shadow" or "phantom" key codes always came either before (or after, I forget) the normal key code, if they were present.

However, on my iPAQ 3970, I found that the shadow key codes came after the regular key code on the dpad, but before on the other hardware buttons.

Any comments?