Java的:在运行全屏应用程序中使用的机器人 [英] Java: use Robot while running fullscreen app

查看:235
本文介绍了Java的:在运行全屏应用程序中使用的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java Robot类的一个问题:有时当我运行全屏游戏不起作用。这里是我的code:

I have a problem with Robot class in Java: it sometimes doesn't work when i run a fullscreen game. Here's my code:

Toolkit tlkt = Toolkit.getDefaultToolkit();
Robot bot = new Robot();
while(true) {
    Thread.sleep(3000);
    tlkt.beep(); //make sure that program still runs
    bot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
    bot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
}

我要左键单击每3秒和蜂鸣是肯定的。它做工精细,但是当我运行某些全屏应用程序,那么它就会发出蜂鸣声,但不能点击。

I want to left-click every 3 seconds and beep for sure. It work fine but when I run some full-screen application, then it just beeps but not click.

我已经尝试过的机器人声明移至循环,所以新的机器人创建的每个时间,但没有sucess。

I already tried to move the Robot declaration into the loop, so new Robot is created every time, but with no sucess.

我已经尝试过了5条不同的游戏,在其中3甚至全屏的工作得很好,但在二没有工作,但只响了。任何帮助吗?

I have tried it on 5 different games, on 3 of them it worked fine even with fullscreen, but on 2 it didnt work but only beeped. Any help?

推荐答案

假设你是在Windows计算机上,以 java.awt.Robot中的呼叫通话将被重定向到 sun.awt.windows.WRobotPeer ,这反过来又要求在 awt_Robot.cpp 本地code。您可以检查 awt_Robot.cpp 这里的源$ C ​​$ C:的http://www.koders.com/cpp/fidFFE004659A9CAB3DA2B3302C457E624AF6F3EEDF.aspx?s=GetDIBits#L232

Assuming you are on a Windows machine, the call to java.awt.Robot calls are redirected to sun.awt.windows.WRobotPeer, which in turn calls native code in awt_Robot.cpp. You can check the source code of the awt_Robot.cpp here : http://www.koders.com/cpp/fidFFE004659A9CAB3DA2B3302C457E624AF6F3EEDF.aspx?s=GetDIBits#L232

在这里,您可以看到鼠标事件与Win32调用实现 mouse_event(...)(在WINUSER.H定义)

Here you can see that the mouse events are realized with win32 call mouse_event(...) (defined in winuser.h)

所以,你的机器人鼠标点击呼叫通过 mouse_event(...)的局限性限制

So your Robot mouse click calls are limited by the limitations of mouse_event(...).

然后在这一点谷歌上搜索,发现,有些游戏有某种宏保护机制。他们无视 mouse_event(...)路由方法,并直接与司机交谈。 Hackshield,例如,提供了这样的保护机制,一些游戏。
因此,这就是为什么有些游戏不接受你的机器人鼠标点击的原因。

Then a little googling on this, reveals that some games have some sort of macro protection mechanism. They ignore mouse_event(...) routed methods and talk directly with the driver. Hackshield, for instance, provides such protection mechanisms to a number of games. So this is the reason why some games do not receive your Robot mouse clicks.

这篇关于Java的:在运行全屏应用程序中使用的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆