title: WinAPI: get typed character
body: <p>I am currently developing a programm called "Key-O-Meter". This programm should track every input made with the keyboard on Windows. The tracked keys will be used to create a statistic at some other time. Unfortunately I am facing problems in determining which character was typed. The code below only prints the character on the keyboard (i.e. "a" if a was pressed, but not "A" if shift + "a" were pressed). Special characters don't work at all.</p>
  
  <p>Is there a better WinAPI function than <code>MapVirtualKeyA</code> that provides this functionality?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;windows.h&gt;
  
  using namespace std;
  
  LRESULT WINAPI lowLevelKeyboardProc(int nCode, WPARAM wParam,
          LPARAM lParam);
  
  /**
   *
   */
  int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
          LPSTR lpCmdLine, int nCmdShow) {
      //add hook
      HHOOK hook;
      hook = SetWindowsHookEx(WH_KEYBOARD_LL,
              (HOOKPROC) lowLevelKeyboardProc, NULL, 0);
  
      //start message loop
      MSG message;
      while (GetMessage(&amp;message, NULL, 0, 0) != 0) {
          TranslateMessage(&amp;message);
          DispatchMessage(&amp;message);
      }
  
      //disable hook
      UnhookWindowsHookEx(hook);
      return 0;
  }
  
  /**
   *
   */
  LRESULT WINAPI lowLevelKeyboardProc(int nCode, WPARAM wParam,
          LPARAM lParam) {
      if (wParam == WM_KEYDOWN) {
          //handle normal keydown
          PKBDLLHOOKSTRUCT hookStruct = (PKBDLLHOOKSTRUCT) lParam;
  
          char keyChar = MapVirtualKeyA(hookStruct-&gt;vkCode, MAPVK_VK_TO_CHAR);
          cout &lt;&lt; keyChar &lt;&lt; endl;
      }
  
      return CallNextHookEx(0, nCode, wParam, lParam);
  }
  </code></pre>