eightban's memo

残しておきたい記事をまとめてみました。このブログに書いてあるドキュメントやブログで配布しているファイルの使用によって発生するいかなる損害に対してもこのブログの管理者は責任を負いません。使用する場合は自己責任のもとに使用してください。

AutoIt

autoit で指定したボタンなどの画像を 監視してクリックする (複数画像対応)

更新日:

スクリプト

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "_ImageSearch_UDF.au3"

Global Const $Ask_On_Found = 0
Global Const $Mouse_Move_On_Found = 0
Global Const $Mouse_Click_On_Found = 1
Global Const $iSleep_Time=1500
Global $sCount = 0
Global $_Image_1 = @ScriptDir & "\butonimage1.bmp"
Global $_Image_2 = @ScriptDir & "\butonimage2.bmp"
Global $_Image_3 = @ScriptDir & "\butonimage3.bmp"
Global $_Image_4 = @ScriptDir & "\butonimage4.bmp"
Global $_Image_5 = @ScriptDir & "\butonimage5.bmp"
Global $_title_1 =  "autoimageclose"
Global $_msg_0 =  "  image"
Global $_msg_1 =  "* image"

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
$mainwindow = GUICreate($_title_1, 140,200)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$msg1="stopping"
$labelx=GUICtrlCreateLabel($msg1, 70, 25)
$buttonx = GUICtrlCreateButton("push", 10, 20,50, 25)
$button1 = GUICtrlCreateButton("set1", 10, 50,50, 25)
$button2 = GUICtrlCreateButton("set2", 10, 80,50, 25)
$button3 = GUICtrlCreateButton("set3", 10, 110,50, 25)
$button4 = GUICtrlCreateButton("set4", 10, 140,50, 25)
$button5 = GUICtrlCreateButton("set5", 10, 170,50, 25)
GUICtrlSetOnEvent($buttonx, "OKButtonx")
GUICtrlSetOnEvent($button1, "OKButton1")
GUICtrlSetOnEvent($button2, "OKButton2")
GUICtrlSetOnEvent($button3, "OKButton3")
GUICtrlSetOnEvent($button4, "OKButton4")
GUICtrlSetOnEvent($button5, "OKButton5")
$Pic1 = GUICtrlCreatePic($_Image_1, 70, 50, 50, 25)
$Pic2 = GUICtrlCreatePic($_Image_2, 70, 80, 50, 25)
$Pic3 = GUICtrlCreatePic($_Image_3, 70, 110, 50, 25)
	$Pic4 = GUICtrlCreatePic($_Image_4, 70, 140, 50, 25)
	$Pic5 = GUICtrlCreatePic($_Image_5, 70, 170, 50, 25)
	$label1=GUICtrlCreateLabel($_msg_0, 65,60)
$label2=GUICtrlCreateLabel($_msg_0, 65,90)
$label3=GUICtrlCreateLabel($_msg_0, 65,120)
$label4=GUICtrlCreateLabel($_msg_0, 65,150)
$label5=GUICtrlCreateLabel($_msg_0, 65,180)
GUICtrlSetColor($label1, 0xff0000)
GUICtrlSetColor($label2, 0xff0000)
GUICtrlSetColor($label3, 0xff0000)
GUICtrlSetColor($label4, 0xff0000)
GUICtrlSetColor($label5, 0xff0000)
GUICtrlSetBkColor($label1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetBkColor($label2, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetBkColor($label3, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetBkColor($label4, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetBkColor($label5, $GUI_BKCOLOR_TRANSPARENT)


GUISetState(@SW_SHOW)
WinWait($_title_1)
WinActivate($_title_1)
WinSetOnTop($_title_1, "", 1)

While 1
	Sleep($iSleep_Time)
  if $msg1="stopping"  Then
	Else
	GUICtrlSetData ($labelx, $msg1)

	GUICtrlSetData ($label5, $_msg_0)
	GUICtrlSetData ($label1, $_msg_1)
    _osu($_Image_1)
	GUICtrlSetData ($label1, $_msg_0)
	GUICtrlSetData ($label2, $_msg_1)

    _osu($_Image_2)
    GUICtrlSetData ($label2, $_msg_0)
	GUICtrlSetData ($label3, $_msg_1)

	_osu($_Image_3)
    GUICtrlSetData ($label3, $_msg_0)
	GUICtrlSetData ($label4, $_msg_1)

	_osu($_Image_4)
    GUICtrlSetData ($label4, $_msg_0)
	GUICtrlSetData ($label5, $_msg_1)

	_osu($_Image_5)
  EndIf
WEnd

Func OKButtonx()
;  MsgBox(0, "GUI Event", "You pressed OK!")
if $msg1="stopping"  Then
  $msg1="executing"

Else
  $msg1="stopping"
EndIf
GUICtrlSetData ($labelx, $msg1)


EndFunc


Func OKButton1()
 _imageget($_Image_1,$Pic1)
EndFunc
Func OKButton2()
 _imageget($_Image_2,$Pic2)
EndFunc
Func OKButton3()
 _imageget($_Image_3,$Pic3)
EndFunc
Func OKButton4()
 _imageget($_Image_4,$Pic4)
EndFunc
Func OKButton5()
 _imageget($_Image_5,$Pic5)
EndFunc

Func _imageget($imgx="",$picx="")

MsgBox(64 + 262144, 'ImageSearch', 'At first, create a file bmp,' & @CRLF & 'photos that will search on the screen!')
_ImageSearch_Create_BMP($imgx)
ConsoleWrite(" Save image: " & $imgx & @CRLF )
Sleep(1000)

GUICtrlSetImage ($picx,$imgx)
EndFunc

Func CLOSEClicked()
 ; MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
Exit
EndFunc


;===========================
Func _osu($imgz="")
If FileExists($imgz) Then

	$sCount += 1
;    Local $return = _ImageSearch($imgz,30)
    Local $return = _ImageSearch_Wait($imgz,100,30)

    If $return[0] = 1 Then
        ConsoleWrite('- [' & $sCount & '] Image found:' & " X=" & $return[1] & " Y=" & $return[2] & @CRLF)
        If $Mouse_Move_On_Found Then
			MouseMove($return[1], $return[2])
			Sleep($iSleep_Time)
		EndIf
        If $Mouse_Click_On_Found Then MouseClick("left", $return[1], $return[2])
        ToolTip('(' & $sCount & "] Image found:" &  " X=" & $return[1] & " Y=" & $return[2], 1, 1)

    EndIf
    Sleep(5000)

EndIf
EndFunc

説明

http://memo.eightban.com/autoit/autoit-_imagesearch_udf

画像を探すのに時間がかかります。その点をご理解の上ご利用ください

監視が不要になった画像はファイルを消してください

その他

コピペした後は下にある文字は次のように変更してください
&#91; [
&amp; &
&lt; <
&gt; >

-AutoIt

Copyright© eightban's memo , 2024 All Rights Reserved Powered by STINGER.