DekAuto4-使用说明文档-鼠标事件


这篇文章主要介绍一下如何使用鼠标点击的相关事件方法,包括鼠标左键、右键、拖拽、图片识别点击、区域识别点击、异步图片识别点击事件等,话不多说,直接上代码:

1、鼠标左键+右键 单击开始按钮

import?controlUtils.ControlEventUtils;
import?events.MouseEvent;

public?class?MouseClickTest?{

????public?static?void?main(String?args[])?throws?Exception?{
????????????ControlEventUtils
????????????????????.mouseEvent(MouseEvent.TYPE_LEFT_CLICK,?30,?1323)
????????????????????.delay(200)
????????????????????.mouseEvent(MouseEvent.TYPE_RIGHT_CLICK,?30,?1323);
????}
}

说明:在上篇文章左键单击开始按钮的基础上直接加上鼠标右键单击,效果如下:

Mose-click-2.gif

2、鼠标拖拽,将电脑管家图标拖至桌面中央

import?controlUtils.ControlEventUtils;
import?events.MouseEvent;
import?events.ShortCutEvent;

public?class?MouseClickTest?{

????public?static?void?main(String?args[])?throws?Exception?{
????????ControlEventUtils
????????????????.shortcutCommand(ShortCutEvent.WINDOWS,?ShortCutEvent.D)
????????????????.delay(200)
????????????????.mouseMove(236,?800)
????????????????.mouseEvent(MouseEvent.TYPE_DRAGMOVE,?1200,?600);
????}
}

效果如下:

Mose-drag-6.gif

3、快捷键win+D返回桌面+图片识别点击“电脑管家”

注:在使用OpenCv相关功能时,一定要先调用intiOpenCvDll,初始化自己本地路径的dll,再进行使用;

代码如下:

import?controlUtils.ControlEventUtils;
import?events.MouseEvent;
import?events.ShortCutEvent;
import?tools.OpenCvUtils;

public?class?MousePicClick?{
????static?String?filePath?=?System.getProperty("user.dir");

????public?static?void?main(String?agrs[])?throws?Exception?{
????????OpenCvUtils.intiOpenCvDll("D:\\openCv-java\\opencv_java401.dll");
????????ControlEventUtils
????????????????.shortcutCommand(ShortCutEvent.WINDOWS,?ShortCutEvent.D)
????????????????.delay(200)
????????????????.mouseEvent(MouseEvent.TYPE_PIC_CLICK,?filePath?+?"\\picTest.png");
???
????}
}

效果如下:

Mose-picClick-3.gif

4、区域图片识别点击:在桌面一定范围内寻找某图,找到后点击该图位置

效果例如下图,从大红框中查找电脑管家的图片,随后点击:

image.png

代码如下:

import?controlUtils.ControlEventUtils;
import?events.MouseEvent;
import?events.ShortCutEvent;
import?tools.OpenCvUtils;

import?java.awt.*;

public?class?MousePicClick?{
????static?String?filePath?=?System.getProperty("user.dir");

????public?static?void?main(String?agrs[])?throws?Exception?{
????????OpenCvUtils.intiOpenCvDll("D:\\openCv-java\\opencv_java401.dll");
????????Rectangle?rectangle?=?new?Rectangle(83,?380,?440,?850);
????????ControlEventUtils
?????????????????.shortcutCommand(ShortCutEvent.WINDOWS,?ShortCutEvent.D)
?????????????????.delay(200)
?????????????????.mouseEvent(MouseEvent.TYPE_AREA_PIC_CLICK,?rectangle,?filePath?+?"\\picTest.png");
???
????}
}

效果如下:

Mose-areaPicClick-4.gif

5、异步等待图片识别点击:可以自行设定等待时间,等待时间内出现该图,则点击,否则跳过该操作,目前该功能在Win10高分辨率电脑上不是很稳定,直接图片识别点击相对稳定;

代码如下:

import?controlUtils.ControlEventUtils;
import?events.MouseEvent;
import?events.ShortCutEvent;
import?tools.OpenCvUtils;

public?class?MousePicClick?{
????static?String?filePath?=?System.getProperty("user.dir");

????public?static?void?main(String?agrs[])?throws?Exception?{
????????OpenCvUtils.intiOpenCvDll("D:\\openCv-java\\opencv_java401.dll");
????????ControlEventUtils
????????????????.shortcutCommand(ShortCutEvent.WINDOWS,?ShortCutEvent.D)
????????????????.delay(200)
????????????????.mouseEvent(MouseEvent.TYPE_PIC_WAIT_CLICK,3000,filePath+"\\picTest.png");
????}
}

效果如下:

Mose-watiPicClick-5.gif


By:JT