Package com.luna.common.swing
Class RobotUtil
java.lang.Object
com.luna.common.swing.RobotUtil
Robot
封装工具类,提供截屏等工具- Since:
- 4.1.14
- Author:
- looly
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedImage
截取全屏static File
captureScreen
(int x1, int y1, int x2, int y2, File outFile) 截屏 截屏的矩形区域static BufferedImage
captureScreen
(Rectangle screenRect) 截屏static File
captureScreen
(Rectangle screenRect, File outFile) 截屏static BufferedImage
captureScreen
(Robot robot, Rectangle screenRect) 对指定设备截屏static File
captureScreen
(File outFile) 截取全屏到文件static void
click()
模拟单击
鼠标单击包括鼠标左键的按下和释放static void
delay()
等待指定毫秒数static int
getDelay()
获取全局默认的延迟时间static Robot
getRobot()
获取 Robot 单例实例static Robot
getRobot
(GraphicsDevice graphicsDevice) static Robot
static GraphicsDevice
static void
keyClick
(int... keyCodes) 模拟键盘点击
包括键盘的按下和释放static void
keyPressString
(String str) 打印输出指定字符串(借助剪贴板)static void
keyPressWithAlt
(int key) alt+ 按键static void
keyPressWithCtrl
(int key) ctrl+ 按键static void
keyPressWithShift
(int key) shift+ 按键static void
static void
mouseMove
(int x, int y) 模拟鼠标移动static void
mouseWheel
(int wheelAmt) 模拟鼠标滚轮滚动static void
模拟右键单击
鼠标单击包括鼠标右键的按下和释放static void
setDelay
(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
-