开发者

Java finding a WINDOW

开发者 https://www.devze.com 2023-04-09 04:43 出处:网络
My desire is to create a bot for a game, inside the constrains of the game rules, that would send information to a web-server.

My desire is to create a bot for a game, inside the constrains of the game rules, that would send information to a web-server. My first problem is to find the game window, and then find its name. I been trying to use Assistive Technologies, but not totally comfortable with them. To my limited understanding I need to add a classpath, or something that would set both projects in the same virtual machine.

I am using netbeans right now, and I when I use: (which I blame)

public void topLevelWindowCreated(Window w) {
    String name = w.getAccessibleContext().getAccessibleName();
    System.out.println("Names of toplevel windows "+name);
    if (!name.equals("Puzzle Pirates"))
        // Only if we're running alongside a Window named "Puzzle Pirates"
        return;
    window = w;
    createGUI();
    frame.setVisible(true);
}

I will get the name of the window I create, but not of the game.

Resources: Game - Puzzle Pirates www.puzzlepirates.com (the download version) Code Examples: http://java.sun.com/javase/tec开发者_运维问答hnologies/accessibility/docs/jaccess-1.1/examples/Explorer/Explorer.java

Hope you can guide me


No, Netbeans isn't to blame.

The classpath bit means that you need to make Puzzle Pirates launch with your bot library available. That means you can't launch PP and the bot in separate Java processes, which is what likely happens if you run the bot from inside Netbeans.

If I understand the sample code comment right, when you put your bot's class name into awt.properties as the example code says, it should get loaded automatically as Puzzle Pirates (or any other Java application) starts. To develop the bot, what you'd have to do is include Puzzle Pirates in your Netbeans project somehow, and start the game, not some test window.


You could always instance puzzle pirates using reflection to load puzzle pirates from your program and thus in the same java process allowing you to hook onto puzzle pirates and grab any necessary information.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号