ControlSendを用います。
ボタンにテキストが表示されている、もしくはボタンの位置が固定されているならば、先にControlClickの利用を検討します。
ClickImageOnControl( image, control )
{
ControlGetPos, ctrlX, ctrlY, ctrlWidth, ctrlHeight, %control%, A
ImageSearch, imageX, imageY, ctrlX, ctrlY, ctrlX + ctrlWidth, ctrlY + ctrlHeight, %image%
if( ErrorLevel = 0 )
{
ControlClick, X%imageX% Y%imageY%
}
else if( ErrorLevel = 1 )
{
MsgBox, Not found.
}
else
{
MsgBox, Problem occurred.
}
}
この関数は、
ClickImageOnControl( "image\Image.bmp", "ToolbarWindow321" )
のように呼び出します。このとき画像ファイルのパスは、作業ディレクトリからの相対パスで指定する必要があります。作業ディレクトリは既定ではAutoHotkeyを実行したディレクトリ (たとえば%ProgramFiles%/AutoHotkey) となるため、そのディレクトリ以下に画像ファイルを配置しないならば、フルパスで記述すべきです。もしくは、
SetWorkingDir, %A_ScriptDir%
のようにして、作業ディレクトリをスクリプトのディレクトリに変更します。
画像ファイルにはgif、jeg、bmpなど各種のフォーマットを使用できますが、色の誤差を考慮するとbmpにすべきです。
コントロールの名前については、Window Spyで調べられます。
コントロールの名前を調べられない場合には、アクティブなウィンドウ全体を対象として画像を検索します。
ClickImage( image )
{
WinGetPos, winX, winY, winWidth, winHeight, A
ImageSearch, imageX, imageY, 0, 0, winWidth, winHeight, %image%
if( ErrorLevel = 0 )
{
ControlClick, X%imageX% Y%imageY%
}
else if( ErrorLevel = 1 )
{
MsgBox, Not found.
}
else
{
MsgBox, Problem occurred.
}
}
画像のファイル名だけを指定して呼び出します。
ClickImage( "image\Image.bmp" )
注意事項は前項の関数と同様です。