[Vm-dev] [Windows cog vm] [Keyboard events related] about keycode mapping

Andreas Raab andreas.raab at gmx.de
Thu Jan 26 21:39:09 UTC 2012


On 1/26/2012 22:29, Guillermo Polito wrote:
>   
>
>
> Hi!
>
> On Thu, Jan 26, 2012 at 4:41 PM, Andreas Raab <andreas.raab at gmx.de 
> <mailto:andreas.raab at gmx.de>> wrote:
>
>
>
>
>     On 1/26/2012 15:43, Guillermo Polito wrote:
>>       
>>
>>
>>     The question is:
>>
>>     Should KeyDown, KeyUp and KeyChar events for the same key produce
>>     the same keyCode?  I think yes.  Because the keyCode indicates
>>     the key pressed in the keyboard. Doesn't it?
>     It does. Which is precisely the reason why it *can't* produce
>     different values when you press the shift key with it.
>
>     The KEY you are pressing does not change depending on the
>     modifier; your OS decides that the combination of the Shift key
>     and the P key produces an uppercase P character. Similarly to the
>     OS deciding that (when using dead keys for example) pressing the
>     accent key followed by the a key produces an accented a. Would you
>     expect the keyDown value for the accented a to change as well?
>     This way lies complete madness.
>
>
> But you're talking about the keychar event and I've not modified at 
> all it's behavior :/.  And yes, I agree I should not do any conversion 
> on KeyUp and KeyDown :).
>
>
>     Maybe you don't understand what these events are used for.
>     Consider you are writing a game and you're using shift and control
>     key for primary and secondary weapon action. Would you expect that
>     the person writing the game needs to handle all of the various
>     control and shift key combos in order to find out that the user
>     pressed the a key to move forward?
>
>
> Oh, yes I do understand.  Maybe I didn't explain me fine, sorry.
>
> The main problem is that I want keycodes to be the same through the 
> three platforms (unix, mac and windows).  And for that, I have to do a 
> mapping somewhere (this piece of code I wrote today was to play and 
> see how it behaves, because the codes are to be defined :) ).
>
> So, I thought those conversions could be done through the *keymap* array.
> Maybe that's not the way to do the mapping, but /the/ mapping should 
> be done somewhere.

The simplest place to do the mapping is inside the image.

Cheers,
   - Andreas

>
> Then, after looking at how other platforms work, I reached the 
> conclusion that if events for the same stroke have different keycodes 
> I don't care :), since the keycode should only be important for KeyUp 
> and KeyDown and not KeyChar (where I should only care about charCode).
>
>
>>     Now, utf32Code should be only used on KeyChar events, and I don't
>>     care about them.
>>
>>     How does it work now?
>>
>>     (KeyDown, KeyUp) and KeyChar events send different keyCodes to
>>     the image.
>
>     Which is exactly the right thing to do.
>
>
> I answered before :).
>
>
>     Cheers,
>       - Andreas
>
>
> Thanks, I'm learning!
> Guille
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20120126/f640553a/attachment.htm


More information about the Vm-dev mailing list