; ; AutoHotkey Version: 1.x ; Language: English ; Platform: Win9x/NT ; Author: A.N.Other ; ; Script Function: ; Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder) ; flag_exe := 0 ;***************************************************** ;*************************************************** ;*************************************************** do_all_commands( cmds ) { global flag_exe Loop % cmds.MaxIndex() { cmd_set := cmds[a_index] prm_bum := cmd_set.MaxIndex() if ( prm_bum >= 2 ) { if ( cmd_set[1] != "" ) { _time := cmd_set[1] } if ( cmd_set[2] != "" ) { _func := cmd_set[2] } } loop_cnt := prm_bum - 2 Loop, %loop_cnt% { var_cnt := 2 + A_Index if ( cmd_set[ var_cnt ] != "" ) { p%A_Index% := cmd_set[ var_cnt ] } } sleep, _time flag_exe := 0 if ( prm_bum == 5 ) { IsFunc(_func) %_func%( p1, p2, p3, _time ) }else if ( prm_bum == 6 ) { IsFunc(_func) %_func%( p1, p2, p3, p4 ) }else if ( prm_bum == 7 ) { IsFunc(_func) %_func%( p1, p2, p3, p4, p5 ) }else if ( prm_bum == 8 ) { if ( _func = "exit" ) { flag := IsFunc(p1) if flag { ret := %p1%( p2, p3,p4, p5, p6 )+0 if ( ret == 2 ){ exit 3 } } }else{ IsFunc(_func) %_func%( p1, p2, p3, p4, p5, p6 ) } } } } WinWaitAndClikButton0(WinTitle,Button,WinText="") {} ControlCheck0(WinTitle,_Button,WinText="") { } ;//-------------------------------------------------- ; p1=[] always do ; p6=1,3,5.. 时候点击鼠标左键 ; p6>= 2 ; ① p7 > 0 : p7--; next ;   ② p7 == 0 : Error exit ; ③ p7 < 0: always loop ; p6 < 2 ; ① p7 > 0 : p7-- ;   ② p7 <= 0 : p1++ next ;------------------------------ ; ret_id = -1 p6 < 2 ; ret_id = -2 p6 >= 2 ;//////////////////////////////////// FindImgTextAndClick(cmds, search_x := 0, search_y := 0, search_w := 0, search_h := 0){ local start_num,pro_id,do_flg,pro_old_id, pro_flg, ok_num,try_cnt, tmp_num,err_num, err_msg local bak_pro_id,bak_p1 if ( search_x == 0 ){ search_x := A_ScreenWidth//2 } if ( search_y == 0 ){ search_y := A_ScreenHeight//2 } if ( search_w == 0 ){ search_w := A_ScreenWidth//2 } if ( search_h == 0 ){ search_h := A_ScreenHeight//2 } start_num := 0 try_cnt := 0 pro_id:=-1 pro_old_id:=-1 pro_flg := 0 err_num:=0 err_msg:="" ret_id := -3 Loop, 7 { p%A_Index%= } DO_FINDIMGTEXTANDCLICK: cmd_cnt := cmds.MaxIndex() - start_num Loop, %cmd_cnt% { try_cnt := -1 tmp_num := a_index + start_num cmd_set := cmds[ tmp_num ] p7= p1 := cmd_set[1] /* if ( cmd_set[ 1 ] != "" ) { _pro_id := cmd_set[1] } */ RETRY_FINDIMGTEXTANDCLICK: bak_p1 := p1 bak_pro_id := pro_id do_flg := 0 if p1= { do_flg := 1 if ( pro_id < 0 ) { pro_id := 0 } } else if ( pro_id == -1 ) { do_flg := 1 pro_id := p1+0 } else if ( pro_id == p1 ) { do_flg := 1 } if ( do_flg == 1) { p6:=1 ;;默认总是1 prm_bum := cmd_set.MaxIndex() Loop, %prm_bum% { var_cnt := A_Index if ( cmd_set[ var_cnt ] != "" ) { p%A_Index% := cmd_set[ var_cnt ] } } /* if p1= { p1 := 0 } */ if ( try_cnt == -1 ){ if p7 = { try_cnt := -1 } else{ try_cnt := p7 } } if ( pro_id > pro_old_id ){ err_msg:="" pro_old_id := pro_id } sleep, p2 WinActivate, %p3% if (ok:=FindText(search_x, search_y, search_w, search_h, 0, 0, p4)) { CoordMode, Mouse X:=ok.1.1, Y:=ok.1.2, W:=ok.1.3, H:=ok.1.4, Comment:=ok.1.5, X+=W//2, Y+=H//2 MouseMove, %X%, %Y% _click := Mod(p6,2) if( _click > 0 ) ;; p6==0时候不点击 Click, %X%, %Y% ok_num := tmp_num-1 pro_flg := 0 err_msg := "" } else{ _retry := p6 //2 if (_retry < 1 ){ if ( try_cnt <= 0 ){ err_num:=0 try_cnt := 0 pro_id++ ;;失败时候pro_id 增加1 pro_flg=1 err_msg := p5 ":" err_msg continue } try_cnt-- /* if ( (tmp_num > 1) &&(err_num != tmp_num ) &&(try_cnt < 2) && (tmp_num > ok_num+1 ) ){ start_num := tmp_num -2 err_msg := p5 ":" err_msg }else{ if ( err_num == tmp_num ) { } } */ p1 := bak_p1 pro_id := bak_pro_id Goto, RETRY_FINDIMGTEXTANDCLICK }else{ if ( try_cnt == 0 ){ err_msg := p5 ":" err_msg MsgBox,can't find -%err_msg% ret_id := -2 return ret_id }else if ( try_cnt > 0 ){ try_cnt-- } p1 := bak_p1 pro_id := bak_pro_id Goto, RETRY_FINDIMGTEXTANDCLICK } } ret_id := pro_id } } if ( pro_flg > 0) { ;MsgBox,can't find -%err_msg% ret_id := -1 } return ret_id+0 } WaitForWinOrNextWin(WinTitle1,_Button,WinText1="",WinTitle2="",WinText2="") { RE_TRY5: WinWait,%WinTitle1%,%WinText1%,3 if ErrorLevel { IfWinNotExist,%WinTitle2%,%WinText2% { sleep,1000 Goto,RE_TRY5 } return 0 } else{ Sleep,500 WinActivate,%WinTitle%,%WinText% Sleep,300 ControlFocus, %_Button%,%WinTitle1%,%WinText1% Sleep,200 SetControlDelay, -1 ;MsgBox,text-%Button%:%WinTitle%:%WinText% ControlClick,%_Button%,%WinTitle1%,%WinText1%,,,NA ;Sleep,500 ;ControlClick,%Button%,%WinTitle%,%WinText% return 2 } } ControlCheck(WinTitle,_Button,WinText="") { local myvar := 0 RE_TRY_CHECK: ;WinGetText, text ,%WinTitle% ; WinGetText WinGetTitle The window found above will be used. ;MsgBox,text-%text% WinWait,%WinTitle%,%WinText%,2000000 if ErrorLevel { } else{ Sleep,500 SetControlDelay, 100 Control,Check, , %_Button%, %WinTitle%, %WinText% Sleep,500 ControlGet, OutputVar, Checked, ,%_Button%,%WinTitle%, %WinText% ;MsgBox,text-%OutputVar% if( OutputVar = 0 ) { if(myvar<5){ myvar++ Goto,RE_TRY_CHECK } } } } ;//////////////////////////////////// WinWaitForText(WinTitle,COUNT,NUM,WinText="") { local myvar=0 local lenth local pos local pos_start local pos_end local OutputVar WINWAIT_TRY: WinWait,%WinTitle%,,COUNT SetTitleMatchMode Fast ;Fast ;RegEx DetectHiddenText, Off WinGetText, text ,%WinTitle% ; WinGetText WinGetTitle The window found above will be used. ;MsgBox,text-%text% local start_char:=NUM-1 StringGetPos, pos_end, text,`r`n, L%NUM% ;MsgBox,OutputVar-%pos_end% if( start_char > 0 ){ StringGetPos,pos_start,text,`r`n, L%start_char% lenth:=pos_end-pos_start-2 pos:=pos_start+3 }else{ lenth:=pos_end pos:=1 } ;MsgBox,OutputVar-%lenth% StringMid, OutputVar, text, pos,lenth ;MsgBox,text-%text% ;MsgBox,OutputVar1-%OutputVar%-- ;MsgBox,OutputVar1-%OutputVar%-**-OutputVar2-%WinText%-- if( OutputVar = WinText ) { Sleep,1000 WinActivate,%WinTitle% }else{ Sleep,1000 if( myvar4000){ sleep, 5000 }else{ sleep, 100 } Sleep,100 WinActivate,%WinTitle%,%WinText% Sleep,100 ControlFocus, %Button%,%WinTitle%,%WinText% Sleep,100 SetControlDelay, -1 ;MsgBox,text-%Button%:%WinTitle%:%WinText% ControlClick,%Button%,%WinTitle%,%WinText%,,,NA ;Sleep,500 ;ControlClick,%Button%,%WinTitle%,%WinText% flag_exe++ WinWaitClose, %WinTitle%, %WinText%, 5000 if ErrorLevel { Goto,RE_TRY } sleep,500 } } ;------------------------------------------------------------------------------------------------ ; Get Explorer and its TreeView handle ; NUM for WinText position WinWaitAndClikButton2(WinTitle,Button,NUM,WinText="") { local myvar=0 local lenth local pos local pos_start local pos_end local OutputVar RE_TRY2: WinWait,%WinTitle%,,200 SetTitleMatchMode Fast ;Fast ;RegEx DetectHiddenText, Off WinGetText, text ,%WinTitle% ; WinGetText WinGetTitle The window found above will be used. ;MsgBox,text-%text% local start_char:=NUM-1 StringGetPos, pos_end, text,`r`n, L%NUM% ;MsgBox,OutputVar-%pos_end% if( start_char > 0 ){ StringGetPos,pos_start,text,`r`n, L%start_char% lenth:=pos_end-pos_start-2 pos:=pos_start+3 }else{ lenth:=pos_end pos:=1 } ;MsgBox,OutputVar-%lenth% StringMid, OutputVar, text, pos,lenth ;MsgBox,text-%text% ;MsgBox,OutputVar1-%OutputVar%-- ;MsgBox,OutputVar1-%OutputVar%-**-OutputVar2-%WinText%-- if( OutputVar = WinText ) { Sleep,1000 WinActivate,%WinTitle% Sleep,300 ControlFocus, %Button%,%WinTitle% Sleep,200 SetControlDelay, -1 ControlClick,%Button%,%WinTitle%,,,,NA }else{ Sleep,3000 Goto,RE_TRY2 } Sleep,2000 IfWinExist,%WinTitle% { WinGetText, text ,%WinTitle% StringGetPos, pos_end, text,`r`n, L%NUM% if( start_char > 0 ){ StringGetPos,pos_start,text,`r`n, L%start_char% lenth:=pos_end-pos_start-2 pos:=pos_start+3 }else{ lenth:=pos_end pos:=1 } ;MsgBox,OutputVar-%lenth% StringMid, OutputVar, text, pos,lenth ;MsgBox,WinTitle-%WinTitle%,WinText-%OutputVar% if( OutputVar = WinText && myvar<5){ myvar++ Goto,RE_TRY2 } } } WinClikAndWaitTime(WinTitle,Button,WinText="",Sec=5) { local myvar=0 RE_TRY3: ;WinGetText, text ,%WinTitle% ; WinGetText WinGetTitle The window found above will be used. ;MsgBox,text-%text% WinWait,%WinTitle%,%WinText%,2000000 if ErrorLevel { } else{ Sleep,500 WinActivate,%WinTitle%,%WinText% Sleep,300 ControlFocus, %Button%,%WinTitle%,%WinText% Sleep,200 SetControlDelay, -1 ;MsgBox,text-%Button%:%WinTitle%:%WinText% ControlClick,%Button%,%WinTitle%,%WinText%,,,NA ;Sleep,500 ;ControlClick,%Button%,%WinTitle%,%WinText% } Sleep,200 IfWinExist,%WinTitle%,%WinText% { ;MsgBox,WinTitle-%WinTitle%,WinText-%WinText% if(myvar<3){ myvar++ Goto,RE_TRY3 } } WinWaitClose,%WinTitle%,%WinText%,%Sec% if ErrorLevel { return 1 } else{ return 0 } } #include %A_ScriptDir%\FindTextFromImg.ahk #include %A_ScriptDir%\Lvm_setItemState.ahk