<div>turning the function into something like the one I paste below gives me the following output in windows:</div><div><br></div><div>for p key:</div><div><br></div><div><div>key: 112 char: 112 type: keyDown</div><div>key: 112 char: 112 type: keystroke</div>
<div>key: 112 char: 112 type: keyUp</div><div><br></div><div>for shift + p key (being character 16 the shift key, since it is the keycode in the platform, still different from the one in unix ¬¬):</div><div><br></div><div>
key: 16 char: 16 type: keyDown</div><div>key: 80 char: 80 type: keyDown</div><div>key: 80 char: 80 type: keystroke</div><div>key: 80 char: 80 type: keyUp</div><div>key: 16 char: 16 type: keyUp</div></div><div><br></div><div>
Regards,</div><div>Guille</div><div><br></div><div>int recordKeyboardEvent(MSG *msg) {</div><div>  sqKeyboardEvent *evt;</div><div>  int alt, shift, ctrl;</div><div>  int keyCode, virtCode, pressCode;</div><div><br></div>
<div>  if(!msg) return 0;</div><div><br></div><div>  alt = GetKeyState(VK_MENU) &amp; 0x8000;</div><div>  shift = (GetKeyState(VK_SHIFT) &amp; 0x8000);</div><div>  ctrl = GetKeyState(VK_CONTROL) &amp; 0x8000;</div><div>  /* now the key code */</div>
<div>  virtCode = mapVirtualKey(msg-&gt;wParam);</div><div>  keyCode = msg-&gt;wParam;</div><div>  /* press code must differentiate */</div><div>  switch(msg-&gt;message) {</div><div>    case WM_KEYDOWN:</div><div>    case WM_SYSKEYDOWN:</div>
<div>      if(virtCode){</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>keyCode = virtCode;</div><div>      }else if(!shift &amp;&amp; keyCode &gt;= 0x41 &amp;&amp; keyCode &lt;= 0x5A){</div><div>
<span class="Apple-tab-span" style="white-space:pre">                </span>  //If shift is not set and is a character we lowercase it</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>  keyCode = keyCode + 32;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>  }else{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>  keyCode = keymap[keyCode &amp; 0xff];</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>  }</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>pressCode = EventKeyDown;</div><div>      /* filter out repeated meta keys */</div><div>      if(msg-&gt;lParam &amp; 0x40000000) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>/* Bit 30 signifies the previous key state. */</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>if(msg-&gt;wParam == VK_SHIFT ||</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>   msg-&gt;wParam == VK_CONTROL ||</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>   msg-&gt;wParam == VK_MENU) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>  /* okay, it&#39;s a meta-key */</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>  return 1;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div>      }</div><div>      break;</div><div>    case WM_KEYUP:</div><div>    case WM_SYSKEYUP:</div><div>      if(virtCode){</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>keyCode = virtCode;</div>
<div>      }else if(!shift &amp;&amp; keyCode &gt;= 0x41 &amp;&amp; keyCode &lt;= 0x5A){</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>  //If shift is not set and is a character we lowercase it</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>  keyCode = keyCode + 32;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>  }else{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>  keyCode = keymap[keyCode &amp; 0xff];</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>  }</div><div>      pressCode = EventKeyUp;</div><div>      break;</div><div>    case WM_CHAR:</div><div>    case WM_SYSCHAR:</div><div>      /* Note: VK_RETURN is recorded as virtual key ONLY */</div>
<div>      if(keyCode == 13) return 1;</div><div>      pressCode = EventKeyChar;</div><div>      break;</div><div>    default:</div><div>      pressCode = EventKeyChar;</div><div>  }</div><div>  /* remove Ctrl+Alt codes for international keyboards */</div>
<div>  if(ctrl &amp;&amp; alt) {</div><div>    ctrl = 0;</div><div>    alt = 0;</div><div>  }</div><div>  </div><div>  /* first the basics */</div><div>  evt = (sqKeyboardEvent*) sqNextEventPut();</div><div>  evt-&gt;type = EventTypeKeyboard;</div>
<div>  evt-&gt;timeStamp = msg-&gt;time;</div><div>  evt-&gt;charCode = keyCode;</div><div>  evt-&gt;pressCode = pressCode;</div><div>  evt-&gt;modifiers = 0;</div><div>  evt-&gt;modifiers |= alt ? CommandKeyBit : 0;</div>
<div>  evt-&gt;modifiers |= shift ? ShiftKeyBit : 0;</div><div>  evt-&gt;modifiers |= ctrl ? CtrlKeyBit : 0;</div><div>  evt-&gt;windowIndex = msg-&gt;hwnd == stWindow ? 0 : (int) msg-&gt;hwnd;</div><div>  evt-&gt;utf32Code = keyCode;</div>
<div>  /* clean up reserved */</div><div>  evt-&gt;reserved1 = 0;</div><div>  /* note: several keys are not reported as character events;</div><div>     most noticably the mapped virtual keys. For those we</div><div>     generate extra character events here */</div>
<div>  if(pressCode == EventKeyDown &amp;&amp; virtCode != 0) {</div><div>    /* generate extra character event */</div><div>    sqKeyboardEvent *extra = (sqKeyboardEvent*)sqNextEventPut();</div><div>    *extra = *evt;</div>
<div>    extra-&gt;pressCode = EventKeyChar;</div><div>  }</div><div>  return 1;</div><div>}</div><br><div class="gmail_quote">On Thu, Jan 26, 2012 at 12:07 PM, Guillermo Polito <span dir="ltr">&lt;<a 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">More on, in the unix vm, the behavior is the following:<br><br>when pressing p:<br><br>key: 112 char: 112 type: keyDown<br>
key: 112 char: 112 type: keystroke<br>key: 112 char: 112 type: keyUp<br><br>when pressing shift + p (P):<br>
key: 254 char: 254 type: keyDown<br>key: 80 char: 80 type: keyDown<br>key: 80 char: 80 type: keystroke<br>key: 80 char: 80 type: keyUp<br><br><br>F1, after adding support for Function keys,<br>key: 16 char: 16 type: keyDown<br>

key: 16 char: 16 type: keyUp<br><br>While in the windows vm:<br><br>when pressing p (the problematic one):<br><br>key: 80 char: 80 type: keyDown<br>
key: 112 char: 112 type: keystroke<br>
key: 80 char: 80 type: keyUp<br>
<br>
when pressing shift + p (P) works the same, since P char value is the same as P virtual key value:<br>
<br>key: 16 char: 16 type: keyDown<br>
key: 80 char: 80 type: keyDown<br>
key: 80 char: 80 type: keystroke<br>
key: 80 char: 80 type: keyUp<br>
<br>
<br>
F1, without touching the code, shares the same keycode than p:<br><br>
key: 112 char: 112 type: keyDown<br>
key: 112 char: 112 type: keyUp<br>
<br>Guille<div class="HOEnZb"><div class="h5"><br><br><div class="gmail_quote">On Thu, Jan 26, 2012 at 11:43 AM, Guillermo Polito <span dir="ltr">&lt;<a href="mailto:guillermopolito@gmail.com" target="_blank">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">
<div>The question is:</div><div><br></div><div>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&#39;t it?</div>


<div><br></div><div>Now, utf32Code should be only used on KeyChar events, and I don&#39;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>


<div><br></div><div>Ok, right now works because in no place in the image keyDown: is handled, but that&#39;s no excuse :).</div><div><br></div><div>Regards,</div><div>Guille</div><div><div><div>
<br><div class="gmail_quote">On Thu, Jan 26, 2012 at 11:17 AM, Guillermo Polito <span dir="ltr">&lt;<a href="mailto:guillermopolito@gmail.com" target="_blank">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&#39;m not generating Char events for F11 ;).  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.  I&#39;m only fixing that:</div>
<div><br></div><div>KeyDown and KeyUp events for p key and F1 keys have different keyCodes.  I&#39;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 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">



 <br>
  
    
  
  <div bgcolor="#FFFFFF" text="#000000"><div><div>
    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>  evt-&gt;type = EventTypeKeyboard;</div>
        <div>  evt-&gt;timeStamp = msg-&gt;time;</div>
        <div><b>  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.  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 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 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 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, having the same keycode in the image
        side with different keys...</div>
      <div><br>
      </div>
      <div>I&#39;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>    case WM_CHAR:</div>
        <div>    case WM_SYSCHAR:</div>
        <div>      /* Note: VK_RETURN is recorded as virtual key ONLY */</div>
        <div>      if(keyCode == 13) return 1;</div>
        <div>    <b>  charCode = keyCode;</b></div>
        <div>      pressCode = EventKeyChar;</div>
      </div>
      <div>     break</div>
      <div>...</div>
      <div> evt-&gt;timeStamp = msg-&gt;time;</div>
      <div>
        <div><b>  evt-&gt;charCode = charCode? charCode : keymap[keyCode
            &amp; 0xff];</b></div>
        <div>
            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&#39;t be using character
    events for handling function keys. There is no &#39;F11 Character&#39; 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>
      - Andreas<br>
    <br>
    <br>
    <blockquote type="cite">
      <div>Guille</div>
    </blockquote>
  </div>

<br></blockquote></div><br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>