I can send a text from my C# WinForm app to another application like Notepad using:
SendKeys.SendWait("Hello");
but I need to send text to an html input element in Firefox. There are several ways to select a target application. This SO Question uses code like:
Process p = Process.GetProcessesByName("notepad").FirstOrDefault();
IntPtr h = p.MainWindowHandle;
SetForegroundWindow(h);
to set the desired app to the foreground so it will receive the text. But this does not work with the app named "firefox", probably because it uses not 1 but 4 processes according to the Task Manager.
I tried another approach: right before calling SendKeys.SendWait
, just switch back to the last active application just like Alt-Tab does, using code from this SO Question, which works for Notepad, and for the Chrome browser, but not for Firefox.
The purpose of this is to get data from a weight measurement device (scale), connected to the RS232 port, to the html input element in the browser. The same principle of simulating a keyboard is routinely used with USB barcode scanners.
Any idea how to do this with Firefox?
Am I perhaps on the wrong track, and are there perhaps much different methods to get text in the keyboard?