关于Java中生成输入的Robot类用法总结

This class is used to generate native system input events for the purposes of test

 

automation, self-running demos, and other applications where control of the

 

mouse and keyboard is needed. The primary purpose of Robot is to facilitate

 

automated testing of Java platform implementations.

 

Using the class to generate input events differs from posting events to the AWT

 

event queue or AWT components in that the events are generated in the

 

platform's native input queue. For example, Robot.mouseMove will actually move

 

the mouse cursor instead of just generating mouse move events.

 

Note that some platforms require special privileges or extensions to access low-

 

level input control. If the current platform configuration does not allow input

 

control, an AWTException will be thrown when trying to construct Robot objects.

 

For example, X-Window systems will throw the exception if the XTEST 2.2

 

standard extension is not supported (or not enabled) by the X server.

 

Applications that use Robot for purposes other than self-testing should handle

 

these error conditions gracefully.

 

 

 

Constructor Summary

Robot()
          Constructs a Robot object in the coordinate system of the primary screen.

Robot(GraphicsDevice screen)
          Creates a Robot for the given screen device.

 

 

Method Summary

 BufferedImage

createScreenCapture(Rectangle screenRect)
          Creates an image containing pixels read from the screen.

(传说中的截屏,保存在BufferedImage里,如果了解过AWT里的画图对BufferedImage一定不陌生)

 voiddelay(int ms)
          Sleeps for the specified time.(和线程里面的睡眠效果一样,只不过现在对象变成了输入端的机器人)
 intgetAutoDelay()
          Returns the number of milliseconds this Robot sleeps after generating an event.
 Color

getPixelColor(int x, int y)
          Returns the color of a pixel at the given screen coordinates.

(类似于画图里面的采色器)

 booleanisAutoWaitForIdle()
          Returns whether this Robot automatically invokes waitForIdle after generating an event.
 voidkeyPress(int keycode)
          Presses a given key.(产生一个类似于你按了一个键的效果)
 voidkeyRelease(int keycode)
          Releases a given key.(同上,只不过这回变成了释放)
 void

mouseMove(int x, int y)
          Moves mouse pointer to given screen coordinates.

(移动鼠标到指定位置)

 void

mousePress(int buttons)
          Presses one or more mouse buttons.

(鼠标按键按下的事件,参数是鼠标上的哪一个键,有左键右键和滑轮)

 void

mouseRelease(int buttons)
          Releases one or more mouse buttons.

(同上,不解释)

 void

mouseWheel(int wheelAmt)
          Rotates the scroll wheel on wheel-equipped mice.

(滚动滑轮,参数的正负代表向上还是向下,参数的值代表滑槽转了几下)

 voidsetAutoDelay(int ms)
          Sets the number of milliseconds this Robot sleeps after generating an event.
 voidsetAutoWaitForIdle(boolean isOn)
          Sets whether this Robot automatically invokes waitForIdle after generating an event.
 StringtoString()
          Returns a string representation of this Robot.
 voidwaitForIdle()
          Waits until all events currently on the event queue have been processed.

04:41:39

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值