此类依赖findtext.ahk,exsleep.ahk,exmath.ahk
声明:
- 所贴出的代码纯属个人原创
- 所有代码经过测试才贴,但不保证所有功能最终完成,可能后续会有更新,欢迎随时回顾
- 所有非原创的代码,会声明,尽量给出引用出处
主要接口
win := new Clickable("ahk_pid 12345", 0.5, true)
win.GetRect()
win.Act()
win.SetPath(exepath)
win.SetSize(width,height)
win.DoClick()
win.DoClick(x:=123,y:=456)
win.FindPic(Text)
win.ClickPic(Text)
win.SimClickPics(0,Text1,Text2...)
win.ClickPics(Text1,Text2...)
;//其中Text由抓图控件(中文版软件某版本自带)自动生成
findtext.ahk
本类由网络下载
exsleep.ahk, exmath.ahk
简单的封装了随机数和随机睡眠
clickable.ahk代码
#Include findtext.ahk
;// #Include exmath.ahk
#Include exSleep.ahk
; @author essdy@csdn
; @version 1.00
CNPID(n)
{
return "ahk_pid " n
}
Class Clickable
{
__New(CN, Indent = 0.5, PIDMOD = false, width = 0, height = 0)
{
this.CN := CN
this.PIDMOD := PIDMOD
if(Indent>0)
this.Indent := Indent
this.BackMode := false
this.Trys := 1
if(width != 0)
{
this.SetSize(width, height)
}
}
SetTrys(n)
{
if(n >= 1)
{
this.Trys := ceil(n)
}
}
UnsetTrys()
{
this.Trys := 1
}
SetBgMode()
{
this.BackMode := true
}
UnsetBgMode()
{
this.BackMode := false
}
SetSize(w,h)
{
SRSleep(this.Indent)
t := this.CN
WinMove,%t%,,,,%w%,%h%
}
GetRect()
{
RTitle :=
RWidth :=
RHeight :=
RX:=
RY:=
WinGetPos, RX, RY, RWidth, RHeight, % this.CN
; WinGetActiveStats, RTitle, RWidth, RHeight, RX, RY
; SRSleep(this.Indent)
RRect := {x:RX,y:RY,width:RWidth,height:RHeight}
return RRect
}
SetPath(exepath, reopenindent = 3)
{
if(exepath == "")
{
this.reopenindent := reopenindent
return
}
if(!FileExist(exepath))
throw Not Found File %exepath%
this.exepath := exepath
this.exepath_set := true
this.reopenindent := reopenindent
}
Act(open = false)
{
CN:=this.CN
SRSleep(this.Indent)
if(!WinExist(CN))
{
if(!open)
throw Not open %CN%
if(!this.exepath_set)
throw Not Exist App %CN%
RunWait % this.exepath
SRSleep(this.reopenindent)
}
if(WinActive(CN))return true
WinActivate % CN
return true
}
DoClick(params*)
{
l := params.Length()
x:=
y:=
SRSleep(this.Indent)
if(l == 2)
{
x:=params[1]
y:=params[2]
if(this.BackMode)
{
pt=x%x% y%y%
SetControlDelay -1
ControlClick, %pt%, % this.CN,,,1,NA Pos
}
else
{
Click,%x% %y%
}
}
}
FindPic(Text, sim = 0)
{
this.Act()
RWidth :=
RHeight :=
RX:=
RY:=
WinGetPos, RX, RY, RWidth, RHeight, % this.CN
return FindText(RX, RY,RWidth, RHeight, sim, sim, Text)
}
ClickPic(Text, sim = 0)
{
MsgBox D
this.Act()
if( ok:= this.FindPic(Text, sim))
{
CoordMode, Mouse
X:=ok.1.x, Y:=ok.1.y, Comment:=ok.1.id
this.DoClick(X,Y)
return true
}
}
SimClickPics(sim, params*)
{
RWidth :=
RHeight :=
RX:=
RY:=
WinGetPos, RX, RY, RWidth, RHeight, % this.CN
For index, param in params
{
CL := param[1]
Failed = 0
if(!(param[1]>0))
continue
loop, % CL
{
TY := this.Trys
loop, % TY
if(ok := findtext(RX, RY, RWidth, RHeight,sim,sim, param[2]))
{
CoordMode, Mouse
X:=ok.1.x, Y:=ok.1.y, Comment:=ok.1.id
this.DoClick(X,Y)
break
}
}
}
}
ClickPics(params*)
{
this.SimClickPics(0, params*)
}
}
LC(s)
{
ls :=
StringLower,ls,s
return ls
}
UC(s)
{
us :=
StringLower,us,s
return us
}
LoadScript(s)
{
if(!InStr(s,"#"))
{
return
}
A_Array := StrSplit(s, "#")
Exists := FileExist(A_Array[1])
if(Exists)
{
R :=
IniRead R, % A_Array[1], % A_Array[2]
RA := {}
loop,Parse,R,`n,`r
{
B_Array := StrSplit(A_LoopField, "=")
Key := LC(Trim(B_Array[1]))
Val := LC(Trim(B_Array[2]))
if(Key == "textx")
{
Val := StrSplit(Val, ",")
for i, v in Val
{
Val[i] := Trim(v)
}
}
RA[Key]:=Val
}
return RA
}
}
ReadIniKey(f, s, k)
{
R:=
IniRead, R, %f%, %s%, %k%
return R
}