title: Simulating keypresses in Visual C++
body: <p>Ok so I might be totally barking up the wrong tree here as I'm not that up to date on Windows programming but here goes.</p>
  
  <p>I'm trying to initiate a simulated keypress in a C++ project in Visual Studio 2010.</p>
  
  <p>Essentially when the program receives a specific code string from another application (which is all being worked via many if statements, messy but works)</p>
  
  <p>I need it to perform the same function as if I pressed control and s on my keyboard.</p>
  
  <p>Now some code I found was this.</p>
  
  <pre><code>keybd_event(VK_LCONTROL,0,0,0); 
    keybd_event(bKey, 0, 0, 0);
  
  
     keybd_event(bKey, 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_LCONTROL,0,KEYEVENTF_KEYUP,0); 
  </code></pre>
  
  <p>Whereby bKey is the appropriate ASCII code for S, it escapes me off hand but still, it's mostly irrelevant to this post.</p>
  
  <p>What this should do by my understanding of it is</p>
  
  <pre><code>Push Control down
  Push S down
  Release S
  Release Control.
  </code></pre>
  
  <p>However it does not seem to do this, it seems to only push down and release S thereby printing S as appropriate or not depending if text entry is available at the time.</p>
  
  <p>Am I barking up the wrong tree altogether here? I know how to do this in Objective C in Xcode but the two seem quite radically different, I know they're different systems but still.</p>
  
  <p>Can anyone propose a solution to this? Basically a way to make the program hit Control + S together (not one after the other, together).</p>
  
  <p>Any help is much appreciated. There seems to be a lot of conflicting information out there.</p>