質問

ウィンドウの形で、私はボタンを作りました、そして、私はそれを送信しようとしています F1 特定のウィンドウ(Firefox、My Computerなどなど)に

私の質問は次のとおりです。

  • ウィンドウの名前でどうすればいいですか? (「Mozilla Firefox」など)
  • プロセスの名前でそれを行うにはどうすればよいですか? (firefox.exeなど)
役に立ちましたか?

解決

ウィンドウ名:

[DllImport("User32.dll")] 
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);  
[DllImport("User32.dll")] 
static extern int SetForegroundWindow(IntPtr hWnd);

IntPtr ptrFF = FindWindow(null, "Mozilla Firefox");
SetForegroundWindow(ptrFF);
SendKeys.SendWait("{F1}");

プロセス名:

Process proc = Process.GetProcessesByName("firefox")[0];
IntPtr ptrFF = proc.Handle;
SetForegroundWindow(ptrFF);
SendKeys.SendWait("{F1}");

他のヒント

をご覧ください Sendkeys クラス。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top