I have searched google on this topic for hours and I am slightly confused. I want to send key strokes to fill in text fields and simulate press of the enter key using c#.
So far I have:
class Program
{
static void Main(string[] args)
{
Process p = Process.Start("File.exe");
p.WaitForInputIdle();
IntPtr hWnd = p.MainWindowHandle;
Command.SendMessage(hWnd,/* */);
}
}
public class Command
{
[DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam);
public void sendReturn(IntPtr hWnd)
{
// do something cool here
}
}
Is there an easier way to do this?
Use PostMessage instead of send message
Usage:
[DllImport("User32.Dll")]
public static extern Int32 PostMessage(IntPtr hWnd, int msg, int wParam, int lParam);
const int WM_KEYDOWN = 0x0100;
const int VK_TAB = 0x09;
PostMessage(process.MainWindowHandle, WM_KEYDOWN, VK_TAB, 1);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.