title: How to use InputSimulator to simulate specific keys on Remote Desktop?
body: <p>Im currently using the InputSimulator v0.1.0.0 to simulate keypresses and/or mouse events over Remote Desktop. Basic keypresses (for example pressing 'a') works, but special characters, like 'tab', 'enter' dont.
  I simulate entering texts with:</p>
  
  <pre><code>InputSimulator.SimulateTextEntry("blabla");
  </code></pre>
  
  <p>but the following only works locally:</p>
  
  <pre><code>InputSimulator.SimulateKeyPress(VirtualKeyCode.TAB);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
  </code></pre>
  
  <p>I searched over the net for working examples but i havent found anything useful. Anyone has idea how to make it work?</p>
  
  <p>Thanks in advance!</p>
  
  <p>-------------------------OWN ANSWER----------------------------------</p>
  
  <p>After googling some more, i have found this article:</p>
  
  <p><a href="http://www.pinvoke.net/default.aspx/user32.keybd_event" rel="nofollow">http://www.pinvoke.net/default.aspx/user32.keybd_event</a></p>
  
  <p>in which there is a good code, that does not solve the InputSimulator problem, but does exactly that i need. Here is the code, and how i used that:</p>
  
  <pre><code>[StructLayout(LayoutKind.Sequential)]
      public struct KEYBOARD_INPUT
      {
          public const uint Type = 1;
          public ushort wVk;
          public ushort wScan;
          public uint dwFlags;
          public uint time;
          public IntPtr dwExtraInfo;
      }
  
      [StructLayout(LayoutKind.Sequential)]
      struct MOUSEINPUT
      {
          public int dx;
          public int dy;
          public uint mouseData;
          public uint dwFlags;
          public uint time;
          public IntPtr dwExtraInfo;
      };
  
      [StructLayout(LayoutKind.Explicit)]
      struct KEYBDINPUT
      {
          [FieldOffset(0)]
          public ushort wVk;
          [FieldOffset(2)]
          public ushort wScan;
          [FieldOffset(4)]
          public uint dwFlags;
          [FieldOffset(8)]
          public uint time;
          [FieldOffset(12)]
          public IntPtr dwExtraInfo;
      };
  
      [StructLayout(LayoutKind.Sequential)]
      struct HARDWAREINPUT
      {
          public uint uMsg;
          public ushort wParamL;
          public ushort wParamH;
      };
  
      [StructLayout(LayoutKind.Explicit)]
      struct INPUT
      {
          [FieldOffset(0)]
          public int type;
          [FieldOffset(4)]
          public MOUSEINPUT mi;
          [FieldOffset(4)]
          public KEYBDINPUT ki;
          [FieldOffset(4)]
          public HARDWAREINPUT hi;
      };
      [DllImport("user32.dll", SetLastError = true)]
      static extern uint SendInput(uint nInputs, IntPtr pInput, int cbSize);
  </code></pre>
  
  <p>And this is how i called the 'press TAB' event:</p>
  
  <pre><code>keybd_event(0x09, 0x0f, 0, 0); // Tab Press
  
  keybd_event(0x09, 0x0f, 0x0002, 0);
  </code></pre>