LoginSignup
3
3

More than 5 years have passed since last update.

プロセス名を元に、そのアプリのウィンドウを操作する

Posted at
Sample_Send_AltTab.ahk
Send, {ALT DOWN}{TAB}

などと書いて、無理やりタスクマネージャーを表示させてどうこうすることはまずやりません。

実行ファイル名がわかっている場合には、Process() 関数でプロセスIDを取得し、それを使って、キーストロークを送信します。

ウィンドウクラス名とかを調べる方が楽な場合が多いですが、こういうやり方もありますよということで。

サンプル

コマンドプロンプトにキーストロークを送信するサンプル

Sample_func_process.ahk
; Sample: Send key stroke to the window from process name.

NotFound = 0

ProgramFileName = cmd.exe

Process, Exist, %ProgramFileName%
PID = %ErrorLevel%

If(PID == NotFound)
{
  MsgBox, Process"%ProgramFileName%" not found.
  ExitApp
}

; activate command prompt.
WinActivate, ahk_pid %PID%
WinWaitActive, ahk_pid %PID%
sleep, 500
; send key stroke to command prompt
ControlSend,  , echo message, ahk_pid %PID%

コマンドプロンプトを起動して、裏に隠した状態でこのスクリプトを実行すると、
コマンドプロンプトが表に出てきて、そこに「echo message」とタイプされます。

参考

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3