title: Taking control of another application with sendkeys or window’s API is not working
body: <p>I have tried to control another application to automate a process we do 100 times a day.  It is simple enough, a few key strokes is all but I have been foiled in all attempts. </p>
  
  <p>ROUND 1:
  I have tried .Net SendKeys to send an alt+c:
  AppActivate("Multichannel Order Manager")  'Get focus to my app I wish to control</p>
  
  <p>THEN: SendKeys.SendWait(‘%C’)  or SendKeys.Send(‘%C’)  or SendKeys.SendWait(‘%c’)  or SendKeys.Send(‘%c’)  have all resulted in nothing happening in my app. 
  If I send the alt and then the ‘c’ the app responds but not to the combo.  When I send them separate the app doesn’t do what I need it to, they have to be together.  All alt key combos fail but single key strokes work.</p>
  
  <p>ROUND 2:
  I tried sending key strokes using the FindWindow and PostMessage API:</p>
  
  <pre><code>    Dim ParenthWnd As New IntPtr(0)
      Dim hWnd As New IntPtr(0)
      Dim iRetval As Integer
  
      ParenthWnd = FindWindowByClass("momwin9c000000", 0)
      If ParenthWnd.Equals(IntPtr.Zero) Then
          Beep()
      Else
  
          iRetval = SendMessage(ParenthWnd, WM_KEYDOWN, Keys.Alt, 0)
          iRetval = SendMessage(ParenthWnd, WM_KEYUP, Keys.C, 0)
          iRetval = PostMessage(ParenthWnd, WM_KEYUP, Keys.Alt, 0)
  
      End If
  </code></pre>
  
  <p>This too failed, maybe because I'm not writing to the correct child window of the app?  I have tried using Spy++ to try to figure this out but don't know what I'm doing wrong.</p>
  
  <p>ROUND 3:
  Using Spy++ I tried to figure out what commands I should be sending but again, maybe I don't fully understand what I should be doing.</p>
  
  <pre><code>    Dim ParenthWnd As New IntPtr(0)
      Dim hWnd As New IntPtr(0)
      Dim iRetval As Integer
  
      ParenthWnd = FindWindowByClass("momwin9c000000", 0)
      If ParenthWnd.Equals(IntPtr.Zero) Then
          Beep()
      Else
          ' Have the window handle 
          Dim ChildhWnd As New IntPtr(0)
          ChildhWnd = FindWindowEx(ParenthWnd, IntPtr.Zero, "momwin9c000000", "MOM Main Menu Toolbar")
          If ChildhWnd.Equals(IntPtr.Zero) = False Then
              iRetval = PostMessage(ParenthWnd, WM_KEYUP, &amp;H12, &amp;HD0380001)
              iRetval = PostMessage(ChildhWnd, WM_KEYUP, Keys.ShiftKey, 0)
              iRetval = PostMessage(ChildhWnd, WM_KEYUP, Keys.Alt, 0)
          End If
      End If
  </code></pre>
  
  <p>ROUND 4:
  On thing I didn't mention is the application window is divided into 2 panels.  I can't tab from one panel to the other but I can (using keyboard) alt+c which is what I'm trying to accomplish.  So round 4 went to a mouse click approach. I tried moving the mouse position to the know location of the textbox which I'm trying to move focus to, and clicking.</p>
  
  <pre><code>    Cursor.Position = Me.PointToScreen(New Point(200, 180))
      mouse_event(MOUSEEVENTF_LEFTDOWN, 200, 180, 0, 0)
  </code></pre>
  
  <p>This moved the mouse pointer to the center of the textbox in the bottom panel and clicks, however, the focus stays in the top panel and only moves to the next textbox, almost like a tabkey stroke.</p>
  
  <p>SUMMARY:
  I don't understand what the difference is between a actual alt+c keystroke and either the sendkeys version or the Window's API version but the real keystrokes work and my attempts fail. Same with the difference between actual mouse-clicks and my mouse_event api attempt.  What can I do or try different. Any suggestions are appreciated.  I think part of my problem may be solved if I can get a handle to the child window of the main app, but I can't seam to and I'm not sure what I'm doing wrong.</p>
  
  <p>As a test I downloaded a free mouse/keystroke macro recorder.  It failed to control the window worse then me.  </p>