title: Keyboard input via SendInput (Win32 API) doesnt work, hardware one does
body: <p>I have a task where I need to put some mouse clicks on web form displayed in browser, and also do some keyboard input, as fill the text box with numbers or make sequence of pressing down arrows in order to get choice in combo box.</p>
  
  <p>Window handlers I have, coordinates where click too, it works fine for me (very simple function):</p>
  
  <pre><code> extern "C" __declspec(dllexport) void __stdcall PutSingleClick(unsigned hwnd, int x, int y)
  {
  
      SendMessage(((HWND) hwnd), WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(x, y));
      SendMessage(((HWND) hwnd), WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(x, y));
  }
  </code></pre>
  
  <p><strong>My problem appears while I try to send keyboard input, as for example by calling:</strong></p>
  
  <pre><code>extern "C" __declspec(dllexport) void __stdcall PutKeystrokeDown(int times)
  {
      INPUT ip;
      ip.type = INPUT_KEYBOARD;
      ip.ki.time = 0;
      ip.ki.wVk = 0;
      ip.ki.dwExtraInfo = 0;
  
      ip.ki.wScan = VK_DOWN;
  
      for(int i = 0; i &lt; times; i++)
      {
          ip.ki.dwFlags = KEYEVENTF_SCANCODE;
          SendInput(1, &amp;ip, sizeof(INPUT));
          ip.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
          SendInput(1, &amp;ip, sizeof(INPUT));
      }
      ip.ki.dwFlags = KEYEVENTF_SCANCODE;
      ip.ki.wScan = VK_RETURN;
      SendInput(1, &amp;ip, sizeof(INPUT));
      ip.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
      SendInput(1, &amp;ip, sizeof(INPUT));
  }
  </code></pre>
  
  <p>After calling this function nothing done, only in input buffer remains strange character (" ´ " [akcent, dead character] in my case).</p>
  
  <p>While I try to catch what happens by Spy++, mouse events (clicks) are spied correctly (when generated both manually and by program), but keyboard ones not - either program or manual.</p>
  
  <p>While I try utility On screen keyboard (common part of Windows), it works as good as hardware keyboard (numbers was inputed, chosen value are changed....), but no messages is generated.</p>
  
  <p><strong>Any idea how emulate hardware keystrokes and put sequence where I need?</strong></p>
  
  <p>Thanks a lot.</p>