宏录制器/播放器
我正在制作一种宏记录器/播放器,
我已经使用 java.awt.Robot() 等实用程序完成了播放器部分,它模拟基本的人类鼠标/键盘输出命令,读取 XML 文件。
我被困在必须记录该 XML 文件的部分。 我不知道我可以使用哪个类来执行与 Robot() 相反的操作如果您有任何 FemaleRobot() 给我,我会非常高兴:D
到目前为止,我在这个方向上唯一拥有的是:
while (true) {
Point pos = MouseInfo.getPointerInfo().getLocation();
System.out.println(pos.x+" x "+pos.y);
}
这并不多这并不是我真正想要的^_^,我不知道如何使用鼠标/按键监听器,因为它需要一个组件。如果这是唯一的方法,那么我应该使用什么组件,因为我不需要任何图形化java实现?我应该创建一个假组件吗?哪一个?
例如,我希望我的记录器在 XML 中写入我如何单击 ubuntu 桌面或在 firefox 上按 Enter 键。
我想这很清楚,如果不是,我会经常检查答案。祝您有美好的一天,感谢您阅读本文。
I am making a sort of Macro recorder/player
I have done the player part with utils such as java.awt.Robot()
which emulates basic human mouse/keyboard output commands, reading an XML file.
I am stuck at the part where I have to record that XML file.
I have no idea of which Class I can use to do the opposite of Robot() If yo have any FemaleRobot() for me I would be very happy :D
The only thing in this direction I have so far is :
while (true) {
Point pos = MouseInfo.getPointerInfo().getLocation();
System.out.println(pos.x+" x "+pos.y);
}
which is not much and not really what I want ^_^, I don't know how to use a Mouse/KeyListener since it would require a Component. If it is the only way, what Compoment do I use as I don't want any graphical java implementation? Should I create a phony Component anyway? Which one?
e.g. I want my recorder to write in the XML how I click on my ubuntu desktop or press enter on firefox.
I guess it's clear, if not I will be checking the answers a lot. Have a nice day and thanks for reading this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试 jnativehook 库:
http://code.google.com/p/jnativehook/wiki/examples
它非常容易使用,可能会满足您的需求。
Try jnativehook lib:
http://code.google.com/p/jnativehook/wiki/examples
It is very easy to use and may meet your needs.
我很遗憾地通知您,完全不可能监视表单之外的鼠标点击和击键。Java 事件根本不会在表单范围之外触发。
java 这样做的原因是为了消除基于 java 的恶意软件试图窃取敏感数据的可能性。
I regret to inform you it is completely impossible to monitor mouse clicks and keystrokes outside of your form. Java events simply do not fire outside the scope of your form.
The reason java behaves this way is to eliminate the possibility of java based malware attempting to steal sensitive data.
您可以在此处找到鼠标侦听器的示例:http://docs.oracle。 com/javase/tutorial/uiswing/events/mouselistener.html
要写入文件,您可以执行以下操作:
如果您这样做:
您将需要在循环中添加 Thread.Sleep 调用。
然后您可以通过执行以下操作读回文件:
然后您可以解析该字符串以获取值。
因此,您可能会执行以下操作:
您将必须使用鼠标事件将单击位置写入文件。
You can find examples of mouse listeners here: http://docs.oracle.com/javase/tutorial/uiswing/events/mouselistener.html
to Write to a file you can do something like:
If you are doing this:
You will want to add a Thread.Sleep call in the loop.
Then you can read the file back by doing:
Then you can parse that string to get the values.
So you might do something like:
You will have to use the mouse events to write click positions to the file.
你可以先获取屏幕的分辨率。第二件事是制作一个与屏幕大小相同的框架,并将其透明度设置为0%。当你单击屏幕上的某个位置时,放下jframe并使用鼠标机器人单击该位置可以得到整个屏幕的坐标。这样就可以记录鼠标的点击,但是问题来了,当你需要输入文字的时候
You can first get the resolution of screen.Second thing make a frame that is a size of your screen and make its transparency to 0% .When you click to a position on a screen put down your jframe and use mouse robot to click a position.You can get the coordinates of the entire screen.This way you can record the mouse clicks,But the problem comes is when you need to type in the text