title: Simulate key being held down in C and WINAPI
body: <p>I'm working on a project where I took a Super Nintendo controller, driving it with an Arduino. The Arduino reads the button presses on the controller, and sends it over a serial connection.</p>
  
  <p>I'm working on a receiver program, which will read from the serial port, and then simulate key presses in Windows, so I can use the controller in other programs.</p>
  
  <p>The thing is, I got pretty much everything down. Except there is one issue.
  My simulated keypresses aren't actually being held down.</p>
  
  <p>Here is the code for the A button (buttons are active low, so they are 'false' when being pressed)</p>
  
  <pre><code>if(!(buttonState.state_word &amp; B_A))
  {
      /* If previous state is not pressed, and current is pressed, simulate a keypress */
      if(prevState.state_word &amp; B_A)
          keybd_event(0x41, 0x41,KEYEVENTF_EXTENDEDKEY | 0,0);
  }
  else if(buttonState.state_word &amp; B_A)
  {
      /* If previous state is pressed, and current is not pressed, simulate a key release */
      if(!(prevState.state_word &amp; B_A))
          keybd_event(0x41, 0x41,KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0);  
  }
  </code></pre>
  
  <p>When I press A on the SNES controller, an A will appear in notepad, for example.
  And when I hold the A button on the SNES controller, a single A will appear in notepad, but the terminal will print that the key is being held, like I programmed it to do.</p>
  
  <p>When the button is first pressed from being unpressed, it simulates the keypress. When it's held down, no more calls to simulate a keypress are made. And then when the SNES button is released, the keypress is also released.</p>
  
  <p>Since there is this time between the keydown and the keyup, why is there only a single letter being printed, and not as if the keyboard was being held down and printing repeatedly?</p>