Package com.luna.common.swing
Class RobotUtil
java.lang.Object
com.luna.common.swing.RobotUtil
Robot 封装工具类,提供截屏等工具- Since:
- 4.1.14
- Author:
- looly
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedImage截取全屏static FilecaptureScreen(int x1, int y1, int x2, int y2, File outFile) 截屏 截屏的矩形区域static BufferedImagecaptureScreen(Rectangle screenRect) 截屏static FilecaptureScreen(Rectangle screenRect, File outFile) 截屏static BufferedImagecaptureScreen(Robot robot, Rectangle screenRect) 对指定设备截屏static FilecaptureScreen(File outFile) 截取全屏到文件static voidclick()模拟单击
鼠标单击包括鼠标左键的按下和释放static voiddelay()等待指定毫秒数static intgetDelay()获取全局默认的延迟时间static RobotgetRobot()获取 Robot 单例实例static RobotgetRobot(GraphicsDevice graphicsDevice) static Robotstatic GraphicsDevicestatic voidkeyClick(int... keyCodes) 模拟键盘点击
包括键盘的按下和释放static voidkeyPressString(String str) 打印输出指定字符串(借助剪贴板)static voidkeyPressWithAlt(int key) alt+ 按键static voidkeyPressWithCtrl(int key) ctrl+ 按键static voidkeyPressWithShift(int key) shift+ 按键static voidstatic voidmouseMove(int x, int y) 模拟鼠标移动static voidmouseWheel(int wheelAmt) 模拟鼠标滚轮滚动static void模拟右键单击
鼠标单击包括鼠标右键的按下和释放static voidsetDelay(int delayMillis) 设置默认的延迟时间
当按键执行完后的等待时间,也可以用ThreadUtil.sleep方法代替
-
Constructor Details
-
RobotUtil
public RobotUtil()
-
-
Method Details
-
main
-
getRobot
获取 Robot 单例实例- Returns:
Robot单例对象- Since:
- 5.7.6
-
getDelay
public static int getDelay()获取全局默认的延迟时间- Returns:
- 全局默认的延迟时间
- Since:
- 5.7.6
-
setDelay
public static void setDelay(int delayMillis) 设置默认的延迟时间
当按键执行完后的等待时间,也可以用ThreadUtil.sleep方法代替- Parameters:
delayMillis- 等待毫秒数- Since:
- 4.5.7
-
mouseMove
public static void mouseMove(int x, int y) 模拟鼠标移动- Parameters:
x- 移动到的x坐标y- 移动到的y坐标- Since:
- 4.5.7
-
click
public static void click()模拟单击
鼠标单击包括鼠标左键的按下和释放- Since:
- 4.5.7
-
rightClick
public static void rightClick()模拟右键单击
鼠标单击包括鼠标右键的按下和释放- Since:
- 4.5.7
-
mouseWheel
public static void mouseWheel(int wheelAmt) 模拟鼠标滚轮滚动- Parameters:
wheelAmt- 滚动数,负数表示向前滚动,正数向后滚动- Since:
- 4.5.7
-
keyClick
public static void keyClick(int... keyCodes) 模拟键盘点击
包括键盘的按下和释放- Parameters:
keyCodes- 按键码列表,见KeyEvent- Since:
- 4.5.7
-
keyPressString
打印输出指定字符串(借助剪贴板)- Parameters:
str- 字符串
-
keyPressWithShift
public static void keyPressWithShift(int key) shift+ 按键- Parameters:
key- 按键
-
keyPressWithCtrl
public static void keyPressWithCtrl(int key) ctrl+ 按键- Parameters:
key- 按键
-
keyPressWithAlt
public static void keyPressWithAlt(int key) alt+ 按键- Parameters:
key- 按键
-
captureScreen
截取全屏- Returns:
- 截屏的图片
-
captureScreen
截取全屏到文件- Parameters:
outFile- 写出到的文件- Returns:
- 写出到的文件
-
captureScreen
截屏- Parameters:
screenRect- 截屏的矩形区域- Returns:
- 截屏的图片
-
getRobot
-
captureScreen
对指定设备截屏- Parameters:
robot-screenRect-- Returns:
-
captureScreen
截屏- Parameters:
screenRect- 截屏的矩形区域outFile- 写出到的文件- Returns:
- 写出到的文件
-
captureScreen
截屏 截屏的矩形区域- Parameters:
x1-y1-x2-y2-outFile- 写出到的文件- Returns:
- 写出到的文件
-
delay
public static void delay()等待指定毫秒数 -
getRobot
-
getScreenDevice
-