title: Sending keyboard commands to DOSBOX from C#
body: <p>I want to send a single keyboard command (down arrow) to DOSBOX, followed by executing some processing code in C#, then looping. My aim is to automate the running of a DOS program.</p>
  
  <p>The code I have works successfully on Notepad and Windows Explorer however will not work on DOSBOX.</p>
  
  <p>This is my (simplified) code:</p>
  
  <pre><code>[DllImport("user32.dll")]
  public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
  
  static void Main(string[] args)
  {
      Console.ReadKey();
      System.Threading.Thread.Sleep(2000); //to give me time to set focus to the other window
      SendMessage(new IntPtr(0x001301CE), 0x0100, new IntPtr(0x28), new IntPtr(0));
  }
  </code></pre>
  
  <p>I obtained the handle for the window using WinSpy++, DOSBOX only has one window and no child windows and this process works fine for notepad and explorer. The other perameters I'm sending to the SendMessage method are the code for the <a href="http://msdn.microsoft.com/en-gb/library/windows/desktop/ms646280%28v=vs.85%29.aspx" rel="nofollow">keyboard notification keydown</a> and the code for the <a href="http://msdn.microsoft.com/en-gb/library/windows/desktop/dd375731%28v=vs.85%29.aspx" rel="nofollow">down arrow key</a>.</p>
  
  <p>So my question is, how can I modify my code to send keypresses to DOSBOX, or is there a different way that I can achieve this?</p>