使用按键精灵识别点击区域进行点击

使用按键精灵,我们可以录制脚本,根据组件坐标进行一些自动化的操作。

但是,有时组件的坐标可能不是一定的,会发生细微的变化。

我们可以根据图片识别点击区域进行点击。

一、获取点击区域图片

1.打开按键精灵软件,点击抓抓

 

 2.点击图像->截屏->框选区域->位图另存为,存储位图(bmp)。

 

 3.在附件中添加该位图(bmp)为附件。

 

 二、书写脚本

1.新建一个脚本

2.输入如下代码

复制代码
Dim intX, intY
Rem 开始找图
FindPic 0, 0, 1920, 1080, "Attachment:\test2.bmp", 0.9, intX, intY
TracePrint intX
TracePrint intY
If intX > 0 And intY > 0 Then 
MoveTo intX+20,intY+20
LeftClick 1
Delay 100
Goto 开始找图
 
Else 
Delay 500
Goto 开始找图
 
End If
复制代码

其中,1920和1080是屏幕的分辨率。

3.点击调试->启动,则会输出点击区域图片的坐标值,并自动进行点击操作。

4.下面是寻找多个点击位置,并进行点击的代码

复制代码
Dim intX, intY
Rem 开始找图
FindPic 0, 0, 1920, 1080, "Attachment:\circle.bmp", 0.9, intX, intY
TracePrint intX
TracePrint intY
If intX > 0 And intY > 0 Then 
MoveTo intX+20,intY+20
LeftClick 1
Delay 100
Else 
Delay 500
End If

FindPic 0, 0, 1920, 1080, "Attachment:\confirm.bmp", 0.9, intX, intY
TracePrint intX
TracePrint intY
If intX > 0 And intY > 0 Then 
MoveTo intX+20,intY+20
LeftClick 1
Delay 100
Else 
Delay 500
End If

FindPic 0, 0, 1920, 1080, "Attachment:\continue.bmp", 0.9, intX, intY
TracePrint intX
TracePrint intY
If intX > 0 And intY > 0 Then 
MoveTo intX+20,intY+20
LeftClick 1
Delay 100
Else 
Delay 500
End If

FindPic 0, 0, 1920, 1080, "Attachment:\next.bmp", 0.9, intX, intY
TracePrint intX
TracePrint intY
If intX > 0 And intY > 0 Then 
MoveTo intX+20,intY+20
LeftClick 1
Delay 100
Else 
Delay 500
End If

Goto 开始找图
复制代码

即可。

posted @   罗毅豪  阅读(18174)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示