0

I want to send message to the component which has focus from my application(running in background). But in some cases, I don't know how to get their handle. (Especially for web page component).

For example:

  1. Windows 10 calculator:
    I want to automatically input some numbers into it using my application
  2. Chrome, open www.google.com:
    I want to automatically input something into its search inputbox
  3. open cmd.exe:
    I want to automatically input some cmd

The only thing I know is the handle of the main window (can be obtained by spy++). But for the applications above, EnumChildWindows return 0 child.

Is there any solution?

camino
  • 10,085
  • 20
  • 64
  • 115
  • That is "Desktop Automation". There are existing applications for that. Anything in .NET requires leaving managed Code and going down to the Windows API. – Christopher Apr 07 '18 at 17:26
  • To some degree anything but 1 can be done via Process and the Commandline/RunDialog. 2. Can be done via via a simple command to open the page to windows. Programms still use the age old commandline way to getting what they should open. And chrome should have some single instance approach. 3. Again, just run the command via Run/Process. If your programm starts a console itself, you could even get do full I/O rediction to manipulate it however you wanted. – Christopher Apr 07 '18 at 17:30
  • UWP applications (like the Windows 10 calculator) do not use a native `HWND` for their visuals. To automate a UWP application you'll need to use [UI Automation](https://learn.microsoft.com/en-us/dotnet/framework/ui-automation/ui-automation-overview). UI Automation is also the only reliable way to automate web pages rendered in a browser. – IInspectable Apr 07 '18 at 17:30
  • I found a solution here : https://stackoverflow.com/a/1918108/440403 – camino Apr 07 '18 at 21:45
  • No, that's not the solution. As explained in the documentation for [keybd_event](https://msdn.microsoft.com/en-us/library/ms646304.aspx), you should be using [SendInput](https://msdn.microsoft.com/en-us/library/ms646310.aspx) instead. And if you are serious about automating a UI, use UI Automation, as explained in my previous comment. Among others, it allows you to reliably interact with UI widgets, like buttons, menus, etc. – IInspectable Apr 10 '18 at 08:00
  • @IInspectable I see. I will try the UI Automation. Thanks a lot! – camino Apr 11 '18 at 00:50

0 Answers0