当前位置: 技术问答>java相关
请问JAVA怎么模拟鼠标和键盘事件[200分]
来源: 互联网 发布时间:2015-10-17
本文导语: 比如要求模拟鼠标在左下角的[开始]上点一下 多谢 | 看看java.awt.Robot这个类,可能对你有帮助 Class Robot This class is used to generate native system input events for the purposes of test automation, self-...
比如要求模拟鼠标在左下角的[开始]上点一下
多谢
多谢
|
看看java.awt.Robot这个类,可能对你有帮助
Class 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
Class 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
|
有意思,又是按我也看看
|
up
|
鸟国话没学好,惨。。。。。。。。。。
|
有谁能翻译一下?
|
好强,
to (hhv)
大侠,问一下,那么截取屏幕图像,同截取用户按键用哪个类呀~~~~~!
to (hhv)
大侠,问一下,那么截取屏幕图像,同截取用户按键用哪个类呀~~~~~!
|
截取屏幕图像可以用过ROBOT类中的方法
public BufferedImage createScreenCapture(Rectangle screenRect)
不过我没有是过
截取用户按键,我也不知道
你可以试试。
public BufferedImage createScreenCapture(Rectangle screenRect)
不过我没有是过
截取用户按键,我也不知道
你可以试试。
|
我试了以下截取屏幕图像是可以的,代码如下
import java.awt.*;
import java.awt.image.*;
import com.sun.image.codec.jpeg.*;
import java.io.*;
public class ScCap
{
public static void main(String[] args) throws Exception
{
Robot r=new Robot();
Rectangle rect=new Rectangle(0,0,500,500);
BufferedImage bimg=r.createScreenCapture(rect);
FileOutputStream fo=new FileOutputStream("a.jpeg");
JPEGImageEncoder jer=JPEGCodec.createJPEGEncoder(fo);
jer.encode(bimg);
fo.close();
}
}
import java.awt.*;
import java.awt.image.*;
import com.sun.image.codec.jpeg.*;
import java.io.*;
public class ScCap
{
public static void main(String[] args) throws Exception
{
Robot r=new Robot();
Rectangle rect=new Rectangle(0,0,500,500);
BufferedImage bimg=r.createScreenCapture(rect);
FileOutputStream fo=new FileOutputStream("a.jpeg");
JPEGImageEncoder jer=JPEGCodec.createJPEGEncoder(fo);
jer.encode(bimg);
fo.close();
}
}
|
截取用户按键估计应该用window hook吧
|
和木马差不多了~~~
强!!
强!!
|
gz
|
截取用户按键,我也不知道
|
呵呵!
拒绝访问本地文件也没用了!
你抓图了!
呵呵!
爽!
学习一下!
拒绝访问本地文件也没用了!
你抓图了!
呵呵!
爽!
学习一下!
|
不知道在APPLET中可不可以用。