Robot无法在虚拟机内部工作

Robot无法在虚拟机内部工作

本文介绍了Java awt.Robot无法在虚拟机内部工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用java.awt.Robot类在虚拟机内进行测试。如果我在我的主机上测试它,一切都按预期工作,但是当我在虚拟机中运行相同的程序时,没有任何反应,也没有错误/异常。我尝试在不同的计算机上运行Windows XP或Windows 7的内部虚拟机,它从未运行过。

I'm trying to use the java.awt.Robot class for testing inside a virtual machine. Everything works as expected if I test it in my host computer, but when I run the same program inside a virtual machine, nothing happens and there is no error/exceptions. I have tried inside virtual machines running Windows XP or Windows 7 on different computers and it never worked.

我在机器上测试的代码非常简单:

The code I used for testing on the machines was very simple:

try
{
    final Robot robot = new Robot();
    robot.mouseMove(500, 500);
}
catch (AWTException e)
{
    e.printStackTrace();
}

当我运行它时,程序刚刚结束,鼠标不动。机器人类是否在虚拟机中不起作用?如果没有,是否有另一种模拟鼠标移动/点击的方法?您是否曾尝试在虚拟机中使用此类,如果它有效,您的设置是什么?

When I run this, the program just ends and the mouse doesn't move. Is the robot class not working in virtual machines? If it doesn't, is there another way to simulate mouse movement/clicks? Have you ever tried to use this class in a virtual machine and if it worked, what was your setup?

推荐答案

也许它确实如此无法正常工作,因为您已在计算机内安装了访客添加。我正在使用VirtualBox,当我卸载我的Guest Additions程序(在虚拟机控制面板内)时,问题解决了,我的鼠标可以像我在主机上进行的测试一样移动。我希望它对你有所帮助。它对我有用。

Maybe it does not work because you have installed inside your machine Guest Additions. I was using VirtualBox and when I uninstalled my Guest Additions program (inside the virtual machine control panel), the problem was solved and my mouse could move just like the tests I did on my host machine. I hope it helps you. It worked for me.

这篇关于Java awt.Robot无法在虚拟机内部工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:32