简体   繁体   English

在DirectX游戏中模拟Java中的鼠标单击

[英]Simulate Mouse Click in Java in DirectX Game

I am currently using Java's Robot Class within a DirectX game programmed in C++. 我目前在用C ++编程的DirectX游戏中使用Java的机器人类。 I can successfully use the Robot class's mouseMove method, but when I try to use the mouse left click input event, nothing happens. 我可以成功使用Robot类的mouseMove方法,但是当我尝试使用鼠标左键输入事件时,没有任何反应。 I have tried different time spacings between the release and press to no avail. 我尝试了不同的发布和按时间间隔无济于事。 Note: I am currently running eclipse in administrator mode. 注意:我目前正在以管理员模式运行eclipse。 Here is the code: 这是代码:

public class test {
    public static void main(String [] args) throws AWTException, I nterruptedException{
    Robot r = new Robot();

    Thread.sleep(3000);
    for(int i = 0; i<20; i++){
        r.mouseMove(100+i*50, 550);
        Thread.sleep(1);
    }

    Thread.sleep(1000);
    r.mousePress(InputEvent.BUTTON1_MASK);
    Thread.sleep(50);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    Thread.sleep(50);
    r.mousePress(InputEvent.BUTTON1_MASK);
    Thread.sleep(50);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    Thread.sleep(50);
  }
}

Any idea on how to get the mouse click to register? 关于如何使鼠标单击注册的任何想法?

In some games you just cant do this.Depends on the engine and implementation , for instance in source engine games your events will be registered(probably,based on my experience example :CS:GO) , bud unreal engine games might not register anything. 在某些游戏中,您不能执行此操作。取决于引擎和实现,例如,在源引擎游戏中,您的事件将被注册(可能基于我的经验示例:CS:GO),芽虚幻引擎游戏可能未注册任何内容。

Its really common for game developers to actually block some calls of WIN32 mouse_event , which is what Robot API uses.So there is not much you can do to go around it(with Robot api). 对于游戏开发人员来说,实际上阻止WIN32 mouse_event的某些调用是Robot API的用途,因此,使用Robot api可以解决很多问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM