eightban's memo

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

AutoIt

autoit で指定したボタンなどの画像を 監視してウィンドウを自動的に閉じる

更新日:

Image Search UDF

画像認識するものです

https://www.autoitscript.com/forum/files/file/471-image-search-udf/

右側にある Download This fileをクリックします

私はAutoIT_ImageSearchUDFフォルダを作り圧縮ファイルを解凍しました

_ImageSearch_UDF.au3を実行すると DLL ファイルがそのままでは App Folder に作られるので変更します

$_ImageSearchDLL_DIR = @LocalAppDataDir & '\ImageSearchUDF'

$_ImageSearchDLL_DIR = @ScriptDir & '\ImageSearchUDF'

実行すると下記ファイルが作成されます

ImageSearchDLL_MD.dll
ImageSearchDLL_MD_x64.dll
ImageSearchDLL_MDXP.dll
ImageSearchDLL_MDXP_x64.dll
ImageSearchDLL_MT.dll
ImageSearchDLL_MT_x64.dll
ImageSearchDLL_MTXP.dll
ImageSearchDLL_MTXP_x64.dll

_Example_2.au3 これを流すと動きがわかります。画像ファイルも保存してくれてエスケープで止めることができます

gui のサンプル

#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=500
Global $sCount = 0, $_Image_1 = @ScriptDir & "\butonimage.bmp"
Global $_title_1 =  "autoimageclose"

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
$mainwindow = GUICreate($_title_1, 140,80)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$msg1="stopping"
$label1=GUICtrlCreateLabel($msg1, 10, 10)
$button1 = GUICtrlCreateButton("push", 10, 20,50, 25)
$button2 = GUICtrlCreateButton("set", 10, 50,50, 25)
GUICtrlSetOnEvent($button1, "OKButton")
GUICtrlSetOnEvent($button2, "OKButton2")
$Pic1 = GUICtrlCreatePic($_Image_1, 70, 20, 50, 50)
$label2=GUICtrlCreateLabel("image", 80,40)
GUICtrlSetColor($label2, 0xff0000)
GUICtrlSetBkColor($label2, $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
    _osu()
  EndIf
WEnd

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

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


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

GUICtrlSetImage ($Pic1,$_Image_1)
EndFunc

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



;===========================
Func _osu()
	$sCount += 1
;    Local $return = _ImageSearch($_Image_1)
    Local $return = _ImageSearch_Wait($_Image_1,3000,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)


EndFunc

監視する時間や画像の許容値などは変更してください

マウスを動かす,クリックするパラメーターは下記で設定してください

Global Const $Mouse_Move_On_Found = 0
Global Const $Mouse_Click_On_Found = 1

はじめにセットボタンで画像を選んでください。愛する画像を設定したらプッシュボタンで動かしてください

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

-AutoIt

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