title: How to send hardware keyboard or mouse press using any programming language?
body: <p>I found a lot of answers about this question that works in notepad and other programs but doesn't work in a specific game!
  it seems that the game block the inputs from my program.
  here is the programs that I have tried.</p>
  <p>1- using SendInput (c++)</p>
  <pre><code>#include &lt;future&gt;
  #include&lt;Windows.h&gt;
  using namespace std::chrono;
  using namespace std::this_thread;
  using namespace std;
  
  UINT PressKeyScan(WORD scanCode)
  {
      INPUT input[1] = { 0 };
      input[0].type = INPUT_KEYBOARD;
      input[0].ki.wVk = NULL;
      input[0].ki.wScan = scanCode;
      input[0].ki.dwFlags = KEYEVENTF_SCANCODE ;
  
      UINT ret = SendInput(1, input, sizeof(INPUT));
  
      return ret;
  }
  
  UINT ReleaseKeyScan(WORD scanCode)
  {
      INPUT input[1] = { 0 };
      input[0].type = INPUT_KEYBOARD;
      input[0].ki.wVk = NULL;
      input[0].ki.wScan = scanCode;
      input[0].ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
  
  
      UINT ret = SendInput(1, input, sizeof(INPUT));
  
      return ret;
  }
  int main()
  {
      for (size_t i = 0; i &lt; 100; i++)
      {
          PressKeyScan(0x39);
          sleep_for(milliseconds(100));
          ReleaseKeyScan(0x39);
          sleep_for(milliseconds(100));
      }
      
  }
  </code></pre>
  <p>2- using SendKeys (C# winforms)</p>
  <pre><code>private void btnSendKeys_Click(object sender, EventArgs e)
  {
      int iHandle = NativeWin32.FindWindow(null, txtTitle.Text);
      
      NativeWin32.SetForegroundWindow(iHandle);
      
      string keys = &quot;&quot;;
      string space = &quot; &quot;;
      
  
      for (int i = 0; i &lt; lbKeys.Items.Count; i++)
      {
          if (lbKeys.Items[i].Text.ToString() == &quot;{SPACE}&quot;)
          {
              keys += space;
          }
          else
          {
              keys += lbKeys.Items[i].Text.ToString();
          }
      }
  
      System.Windows.Forms.SendKeys.Send(keys);
      
  }
  </code></pre>
  <p>both worked in notepad and some other apps but didn't worked in specific game.</p>