title: Ctrl key kept down after simulating a ctrl key down event and ctrl key up event
body: <p>I have a small program that simulates <kbd>ctr</kbd>+<kbd>c</kbd> &amp; <kbd>ctr</kbd>+<kbd>v</kbd> (copy &amp; paste) events using the system <code>keybd_event</code>. The problem is that after the program runs the computer continues to act as if the <kbd>ctrl</kbd> key is pressed down and then - if I type <kbd>a</kbd> it selects the whole document, if I roll the mouse wheel it changes the text side, etc. It happens not only in Visual Studio editor, but in any other program that was opened while the program ran as Word etc.
  Here is my code:</p>
  
  <pre><code>    //The system keyboard event.
      [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
      static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
  
      public const int KEYEVENTF_EXTENDEDKEY = 0x0001; //Key down flag
      public const int KEYEVENTF_KEYUP = 0x0002; //Key up flag
      public const int VK_LCONTROL = 0xA2; //Left Control key code
      public const int C = 0x43; // C key code
      public const int V = 0x56; // V key code
  
      static void Main(string[] args)
      {
          Thread.Sleep(1000);// So I have time to select something.
  
          //Simulate ctrl+c
          keybd_event(VK_LCONTROL, 0, KEYEVENTF_EXTENDEDKEY, 0);
          keybd_event(C, 0, KEYEVENTF_EXTENDEDKEY, 0);
          keybd_event(C, 0, KEYEVENTF_KEYUP, 0);
          keybd_event(VK_LCONTROL, 0, KEYEVENTF_KEYUP, 0);
  
          //Simulate ctrl+v
          keybd_event(VK_LCONTROL, 0, KEYEVENTF_EXTENDEDKEY, 0);
          keybd_event(V, 0, KEYEVENTF_EXTENDEDKEY, 0);
          keybd_event(V, 0, KEYEVENTF_KEYUP, 0);
          keybd_event(VK_LCONTROL, 0, KEYEVENTF_KEYUP, 0);
      }
  </code></pre>
  
  <p>Does someone know what could I do to solve this problem?</p>