<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <br>
    <br>
    On 1/26/2012 15:43, Guillermo Polito wrote:
    <blockquote
cite="mid:CAOBmb50ZpYh0R8MnWkgfj0r1iGYdT5WGyO-OVRGrLLupgHp94A@mail.gmail.com"
      type="cite">
      <pre wrap=""> </pre>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <div>The question is:</div>
      <div><br>
      </div>
      <div>Should KeyDown, KeyUp and KeyChar events for the same key
        produce the same keyCode? &nbsp;I think yes. &nbsp;Because the keyCode
        indicates the key pressed in the keyboard. Doesn't it?</div>
    </blockquote>
    <br>
    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.<br>
    <br>
    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?<br>
    <br>
    <blockquote
cite="mid:CAOBmb50ZpYh0R8MnWkgfj0r1iGYdT5WGyO-OVRGrLLupgHp94A@mail.gmail.com"
      type="cite">
      <div>Now,&nbsp;utf32Code should be only used on KeyChar events, and I
        don't care about them.</div>
      <div><br>
      </div>
      <div>How does it work now?</div>
      <div><br>
      </div>
      <div>(KeyDown, KeyUp) and KeyChar events send different keyCodes
        to the image.</div>
    </blockquote>
    <br>
    Which is exactly the right thing to do.<br>
    <br>
    Cheers,<br>
    &nbsp; - Andreas<br>
    <br>
    <blockquote
cite="mid:CAOBmb50ZpYh0R8MnWkgfj0r1iGYdT5WGyO-OVRGrLLupgHp94A@mail.gmail.com"
      type="cite">
      <div><br>
      </div>
      <div>Ok, right now works because in no place in the image keyDown:
        is handled, but that's no excuse :).</div>
      <div><br>
      </div>
      <div>Regards,</div>
      <div>Guille</div>
      <div><br>
        <div class="gmail_quote">On Thu, Jan 26, 2012 at 11:17 AM,
          Guillermo Polito <span dir="ltr">&lt;<a
              moz-do-not-send="true"
              href="mailto:guillermopolito@gmail.com">guillermopolito@gmail.com</a>&gt;</span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">Sure!
            <div><br>
            </div>
            <div>I'm not generating Char events for F11 ;). &nbsp;Since F11
              does not generate Char events.</div>
            <div><br>
            </div>
            <div>The problem is that the <i>p</i> key generates the
              same KeyDown event than F11 for the vm. &nbsp;I'm only fixing
              that:</div>
            <div><br>
            </div>
            <div>KeyDown and KeyUp events for p key and F1 keys have
              different keyCodes. &nbsp;I'm not sure if there will still be
              collisions, but right now, they are with the code as it
              is.</div>
            <div><br>
            </div>
            <div>Guille<br>
              <br>
              <div class="gmail_quote">On Thu, Jan 26, 2012 at 11:02 AM,
                Andreas Raab <span dir="ltr">&lt;<a
                    moz-do-not-send="true"
                    href="mailto:andreas.raab@gmx.de" target="_blank">andreas.raab@gmx.de</a>&gt;</span>
                wrote:<br>
                <blockquote class="gmail_quote" style="margin:0 0 0
                  .8ex;border-left:1px #ccc solid;padding-left:1ex">
                  &nbsp;<br>
                  <div bgcolor="#FFFFFF" text="#000000">
                    <div>
                      <div class="h5"> On 1/26/2012 14:52, Guillermo
                        Polito wrote:
                        <blockquote type="cite">
                          <pre> </pre>
                          <br>
                          <fieldset></fieldset>
                          <br>
                          Hi!
                          <div><br>
                          </div>
                          <div>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:</div>
                          <div><br>
                          </div>
                          <div>
                            <div>evt = (sqKeyboardEvent*)
                              sqNextEventPut();</div>
                            <div>&nbsp; evt-&gt;type = EventTypeKeyboard;</div>
                            <div>&nbsp; evt-&gt;timeStamp = msg-&gt;time;</div>
                            <div><b>&nbsp; evt-&gt;charCode = keymap[keyCode
                                &amp; 0xff];</b></div>
                          </div>
                          <div><b><br>
                            </b></div>
                          <div>the problem with that line is that
                            KeyDown and KeyUp events send
                            VirtualKeycodes as keycodes and the Char
                            event sends a unicode char value. &nbsp;And, it
                            makes collisions, since for example</div>
                          <div><br>
                          </div>
                          <div>$p char value is 112</div>
                          <div>and F1 virtual code value is 112 too :P</div>
                          <div><br>
                          </div>
                          <div><a moz-do-not-send="true"
href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms646276%28v=vs.85%29.aspx"
                              target="_blank">http://msdn.microsoft.com/en-us/library/windows/desktop/ms646276(v=vs.85).aspx</a>
                          </div>
                          <div><a moz-do-not-send="true"
href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms646281%28v=vs.85%29.aspx"
                              target="_blank">http://msdn.microsoft.com/en-us/library/windows/desktop/ms646281(v=vs.85).aspx</a>
                          </div>
                          <div><a moz-do-not-send="true"
href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx"
                              target="_blank">http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx</a>
                          </div>
                          <div><br>
                          </div>
                          <div>And so with other keys,&nbsp;having the same
                            keycode in the image side with different
                            keys...</div>
                          <div><br>
                          </div>
                          <div>I'm trying a solution like this,
                            providing in a Char event the keycode
                            without mapping to the image:</div>
                          <div><br>
                          </div>
                          <div>...</div>
                          <div>
                            <div>&nbsp; &nbsp; case WM_CHAR:</div>
                            <div>&nbsp; &nbsp; case WM_SYSCHAR:</div>
                            <div>&nbsp; &nbsp; &nbsp; /* Note: VK_RETURN is recorded as
                              virtual key ONLY */</div>
                            <div>&nbsp; &nbsp; &nbsp; if(keyCode == 13) return 1;</div>
                            <div>&nbsp; &nbsp; <b>&nbsp; charCode = keyCode;</b></div>
                            <div>&nbsp; &nbsp; &nbsp; pressCode = EventKeyChar;</div>
                          </div>
                          <div>&nbsp; &nbsp; &nbsp;break</div>
                          <div>...</div>
                          <div>&nbsp;evt-&gt;timeStamp = msg-&gt;time;</div>
                          <div>
                            <div><b>&nbsp; evt-&gt;charCode = charCode?
                                charCode : keymap[keyCode &amp; 0xff];</b></div>
                            <div> &nbsp; evt-&gt;pressCode = pressCode;</div>
                          </div>
                          <div>...</div>
                          <div><br>
                          </div>
                          <div>changing only the bold lines, and It
                            seems to work.</div>
                          <div><br>
                          </div>
                          <div>What do you think?</div>
                        </blockquote>
                        <br>
                      </div>
                    </div>
                    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
                    &amp; friends are KEYs not CHARACTERs.<br>
                    <br>
                    Cheers,<br>
                    &nbsp; - Andreas<br>
                    <br>
                    <br>
                    <blockquote type="cite">
                      <div>Guille</div>
                    </blockquote>
                  </div>
                  <br>
                </blockquote>
              </div>
              <br>
            </div>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
  </body>
</html>