;Execwith_set_license "%scriptpath%\autoit3.exe"
;includelog "%opsiLogDir%\au3.log" "300"
;killtask "autoit3.exe"

[Execwith_set_license]
#include "%scriptpath%\opsi-autoit-lib.au3"
Func dialog1()
	If WinActive("") Then
		send("{Tab}")
		send("{Enter}")
		opsiLog("adlib func dialog1 sended tab/enter","%opsiLogDir%\au3.log")
	EndIf
EndFunc

AdlibRegister("dialog1")

; exact title match
Opt("WinTitleMatchMode", 3)
$winhandle = 0
$hTimer = TimerInit()
$mylog = FileOpen("%opsiLogDir%\au3.log", 2)
FileWriteLine($mylog,"auto-it started - waiting for the window")
FileClose($mylog)
run("$InstallDir1$\measurect.exe")
Sleep(30000)
AdlibUnRegister("dialog1")

opsiLogWinList("%opsiLogDir%\au3.log")
; BlockInput(1)
$winhandle = opsiwinwait("Measure CT" , "", 30, "%opsiLogDir%\au3.log")
$winhandle = opsiwinactivate($winhandle , "", 20, "%opsiLogDir%\au3.log")
TrayTip ( "opsi-install", "select via menu license window", 3 ,1)
Sleep(1000)
; select via menu license window
opsisend("{ALT}", $winhandle, "%opsiLogDir%\au3.log")
Sleep(1000)
opsisend("{RIGHT}", $winhandle, "%opsiLogDir%\au3.log")
Sleep(1000)
opsisend("{DOWN}", $winhandle, "%opsiLogDir%\au3.log")
Sleep(1000)
opsisend("{ENTER}", $winhandle, "%opsiLogDir%\au3.log")
TrayTip ( "opsi-install", "handle license window", 3 ,1)
Sleep(1000)
$winhandle = opsiwinwait("" , "", 30, "%opsiLogDir%\au3.log")
$winhandle = opsiwinactivate($winhandle , "", 20, "%opsiLogDir%\au3.log")
opsisend("{TAB}", $winhandle, "%opsiLogDir%\au3.log")
Sleep(1000)
opsisend("{TAB}", $winhandle, "%opsiLogDir%\au3.log")
Sleep(1000)
opsisend("{TAB}", $winhandle, "%opsiLogDir%\au3.log")
Sleep(1000)
opsisend("$LicenseKey$", $winhandle, "%opsiLogDir%\au3.log")
Sleep(1000)
opsisend("{ENTER}", $winhandle, "%opsiLogDir%\au3.log")
TrayTip ( "opsi-install", "leave application", 3 ,1)
Sleep(1000)

$winhandle = opsiwinactivate("Measure CT" , "", 20, "%opsiLogDir%\au3.log")
; select via menu exit
opsisend("{ALT}", $winhandle, "%opsiLogDir%\au3.log")
Sleep(1000)
opsisend("{UP}", $winhandle, "%opsiLogDir%\au3.log")
Sleep(1000)
opsisend("{ENTER}", $winhandle, "%opsiLogDir%\au3.log")
Sleep(1000)
$winhandle = opsiwinwait("" , "", 30, "%opsiLogDir%\au3.log")
$winhandle = opsiwinactivate($winhandle , "", 20, "%opsiLogDir%\au3.log")
opsisend("{ENTER}", $winhandle, "%opsiLogDir%\au3.log")
Sleep(100)

Exit 0
