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

Andreas Raab andreas.raab at gmx.de
Thu Jan 26 19:41:58 UTC 2012



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.

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?

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

Cheers,
   - Andreas

>
> Ok, right now works because in no place in the image keyDown: is 
> handled, but that's no excuse :).
>
> Regards,
> Guille
>
> On Thu, Jan 26, 2012 at 11:17 AM, Guillermo Polito 
> <guillermopolito at gmail.com <mailto:guillermopolito at gmail.com>> wrote:
>
>     Sure!
>
>     I'm not generating Char events for F11 ;).  Since F11 does not
>     generate Char events.
>
>     The problem is that the /p/ key generates the same KeyDown event
>     than F11 for the vm.  I'm only fixing that:
>
>     KeyDown and KeyUp events for p key and F1 keys have different
>     keyCodes.  I'm not sure if there will still be collisions, but
>     right now, they are with the code as it is.
>
>     Guille
>
>     On Thu, Jan 26, 2012 at 11:02 AM, Andreas Raab
>     <andreas.raab at gmx.de <mailto:andreas.raab at gmx.de>> wrote:
>
>
>         On 1/26/2012 14:52, Guillermo Polito wrote:
>>           
>>
>>
>>         Hi!
>>
>>         I was playing to add Function Ket support in the windows vm
>>         (yep, always the same :P), and looking at the code, I saw
>>         this in the recordKeyboardEvent:
>>
>>         evt = (sqKeyboardEvent*) sqNextEventPut();
>>           evt->type = EventTypeKeyboard;
>>           evt->timeStamp = msg->time;
>>         *  evt->charCode = keymap[keyCode & 0xff];*
>>         *
>>         *
>>         the problem with that line is that KeyDown and KeyUp events
>>         send VirtualKeycodes as keycodes and the Char event sends a
>>         unicode char value.  And, it makes collisions, since for example
>>
>>         $p char value is 112
>>         and F1 virtual code value is 112 too :P
>>
>>         http://msdn.microsoft.com/en-us/library/windows/desktop/ms646276(v=vs.85).aspx
>>         <http://msdn.microsoft.com/en-us/library/windows/desktop/ms646276%28v=vs.85%29.aspx>
>>
>>         http://msdn.microsoft.com/en-us/library/windows/desktop/ms646281(v=vs.85).aspx
>>         <http://msdn.microsoft.com/en-us/library/windows/desktop/ms646281%28v=vs.85%29.aspx>
>>
>>         http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
>>         <http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx>
>>
>>
>>         And so with other keys, having the same keycode in the image
>>         side with different keys...
>>
>>         I'm trying a solution like this, providing in a Char event
>>         the keycode without mapping to the image:
>>
>>         ...
>>             case WM_CHAR:
>>             case WM_SYSCHAR:
>>               /* Note: VK_RETURN is recorded as virtual key ONLY */
>>               if(keyCode == 13) return 1;
>>         *  charCode = keyCode;*
>>               pressCode = EventKeyChar;
>>              break
>>         ...
>>          evt->timeStamp = msg->time;
>>         *  evt->charCode = charCode? charCode : keymap[keyCode & 0xff];*
>>           evt->pressCode = pressCode;
>>         ...
>>
>>         changing only the bold lines, and It seems to work.
>>
>>         What do you think?
>
>         The change makes no sense (it will break most non-ascii input
>         like accents, umlauts, etc). You really shouldn't be using
>         character events for handling function keys. There is no 'F11
>         Character' in any character encoding world-wide so trying to
>         represent F11 as a character is completely futile. You need to
>         use keyDown and keyUp events, since F11 & friends are KEYs not
>         CHARACTERs.
>
>         Cheers,
>           - Andreas
>
>
>>         Guille
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20120126/cc1148d3/attachment.htm


More information about the Vm-dev mailing list