You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SikuliX(Java):如何点击匹配位置右侧25像素处?

SikuliX(Java)点击匹配元素右侧指定位置问题解决方法

你遇到的问题是因为calendar.click()会默认点击Match对象的中心位置,所以即便你通过mouseMove移动了鼠标,执行点击操作时仍会回到原匹配点。

以下是两种可行的解决方式:

方式一:计算目标坐标后直接点击

通过获取匹配元素的坐标,计算出右侧25像素的位置,再调用Screen的点击方法:

Screen screenWithCalendarField = new Screen();
Match calendar = null;

try{
    calendar = screenWithCalendarField.find(new File("D:\\Sikuli\\CalendarField.png").getAbsolutePath());
} catch(Exception e){
    e.printStackTrace(); // 建议添加异常打印,便于排查问题
}

if (calendar != null) {
    // 以匹配元素的中心为基准,向右偏移25像素
    int targetX = calendar.getX() + calendar.getW()/2 + 25;
    int targetY = calendar.getY() + calendar.getH()/2;
    
    // 执行点击
    screenWithCalendarField.click(new Location(targetX, targetY));
}

如果需要以匹配元素的左上角为基准向右偏移,将targetX改为calendar.getX() + 25即可。

方式二:使用Match的offset方法获取目标位置

利用Match的offset方法直接生成偏移后的Location对象,再进行点击:

Screen screenWithCalendarField = new Screen();
Match calendar = null;

try{
    calendar = screenWithCalendarField.find(new File("D:\\Sikuli\\CalendarField.png").getAbsolutePath());
} catch(Exception e){
    e.printStackTrace();
}

if (calendar != null) {
    // 相对于匹配元素的中心,向右偏移25像素(x轴正方向)
    Location targetLoc = calendar.offset(25, 0);
    screenWithCalendarField.click(targetLoc);
}

另外注意:你原代码中的delay(5)和delay(10)参数单位是毫秒,这样的延迟几乎可以忽略,建议根据实际需求调整为合理数值,比如delay(500)表示0.5秒延迟。

内容的提问来源于stack exchange,提问作者Cristina Fierbinteanu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 23:31:28