title: ToAscii/ToUnicode in a keyboard hook destroys dead keys
body: <p>It seems that if you call <code>ToAscii()</code> or <code>ToUnicode()</code> while in a global WH_KEYBOARD_LL hook, and a dead-key is pressed, it will be 'destroyed'.</p>
  
  <p>For example, say you've configured your input language in Windows as Spanish, and you want to type an accented letter <b>á</b> in a program. Normally, you'd press the single-quote key (the dead key), then the letter "a", and then on the screen an accented <b>á</b> would be displayed, as expected.</p>
  
  <p>But this doesn't work if you call <code>ToAscii()</code> or <code>ToUnicode()</code> in a low-level keyboard hook function. It seems that the dead key is destroyed, and so no accented letter <b>á</b> shows up on screen. Removing a call to the above functions resolves the issue... but unfortunately, I need to be able to call those functions.</p>
  
  <p>I Googled for a while, and while a lot of people seemed to have this issue, no good solution was provided.</p>
  
  <p>Any help would be much appreciated!</p>
  
  <p><b>EDIT:</b> I'm calling <code>ToAscii()</code> to convert the virtual-key code and scan code received in my <a href="http://msdn.microsoft.com/en-us/library/ms644985%28VS.85%29.aspx" rel="noreferrer">LowLevelKeyboardProc</a> hook function into the resulting character that will be displayed on screen for the user.</p>
  
  <p>I tried <code>MapVirtualKey(kbHookData->vkCode, 2)</code>, but this isn't as "complete" a function as <code>ToAscii()</code>; for example, if you press Shift + 2, you'll get '2', not '@' (or whatever Shift + 2 will produce for the user's keyboard layout/language).</p>
  
  <p><code>ToAscii()</code> is perfect... until a dead-key is pressed.</p>
  
  <p><B>EDIT2:</b> Here's the hook function, with irrelevant info removed:</p>
  
  <pre><code>LRESULT CALLBACK keyboard_LL_hook_func(int code, WPARAM wParam, LPARAM lParam) {
  
      LPKBDLLHOOKSTRUCT kbHookData = (LPKBDLLHOOKSTRUCT)lParam;
      BYTE keyboard_state[256];
  
      if (code &lt; 0) {
          return CallNextHookEx(keyHook, code, wParam, lParam);
      }
  
      WORD wCharacter = 0;
  
      GetKeyboardState(&amp;keyboard_state);
      int ta = ToAscii((UINT)kbHookData-&gt;vkCode, kbHookData-&gt;scanCode,
                       keyboard_state, &amp;wCharacter, 0);
  
      /* If ta == -1, a dead-key was pressed. The dead-key will be "destroyed"
       * and you'll no longer be able to create any accented characters. Remove
       * the call to ToAscii() above, and you can then create accented characters. */
  
      return CallNextHookEx(keyHook, code, wParam, lParam);
  }
  </code></pre>