Windows アプリケーションからプロセスを開始しています。F4ボタンを押すと、そのプロセスでキーを押すことをシミュレートしたいと思います。どうやってやるの?
F4[後で編集]フォームでキーを押すことをシミュレートしたくありませんが、その過程で開始しました。
F4キーを別のプロセスに送信するには、そのプロセスをアクティブ化する必要があります
http://bytes.com/groups/net-c/230693-activate-other-processは次のことを示唆しています。
その後、リードがこのプロセスにキーストロークを送信するように提案したように、System.Windows.Forms.SendKeys.Send( "{F4}")を使用できる場合があります。
編集:
以下のコード例はメモ帳を実行し、それに「ABC」を送信します。
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace TextSendKeys
{
class Program
{
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
static void Main(string[] args)
{
Process notepad = new Process();
notepad.StartInfo.FileName = @"C:\Windows\Notepad.exe";
notepad.Start();
// Need to wait for notepad to start
notepad.WaitForInputIdle();
IntPtr p = notepad.MainWindowHandle;
ShowWindow(p, 1);
SendKeys.SendWait("ABC");
}
}
}
ウィンドウをフォーカスし (SetForegroundWindow WINAPI)、Windows フォーム SendKeys を使用して F4 を送信できます。