使用按键精灵识别点击区域进行点击
使用按键精灵,我们可以录制脚本,根据组件坐标进行一些自动化的操作。
但是,有时组件的坐标可能不是一定的,会发生细微的变化。
我们可以根据图片识别点击区域进行点击。
一、获取点击区域图片
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 开始找图
即可。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步