Jump to content

BotMouseListener: checkMouseEvent. Trying to register mouse events.


Recommended Posts

Posted

I'm lost on how this part of the API works. I'm trying to do something on the following triggers:

- Mouse down;
- Mouse movement (can be done with getMouse().getPosition(); maybe there's a better way?;
- Mouse up;
- Mouse click (?); might be the combination of mouse down and up;
- Mouse drag (?); might be the combination of mouse down and mouse movement.

Now, I have found the BotMouseListener and the checkMouseEvent which seems promising, but I have not a single clue how to implement it. A push in the right direction or some code snippets would be greatly appreciated!

Posted

BotMouseListener is a class than can be used to record your mouse clicks. In order to recreate them, use the ClientMouseEventHandler

import org.osbot.rs07.input.mouse.BotMouseListener;
import org.osbot.rs07.script.Script;

import java.awt.event.MouseEvent;

public class MouseHandler extends Script {

    private final BotMouseListener mouseListener = new BotMouseListener() {
        @Override
        public void checkMouseEvent(MouseEvent mouseEvent) {
            // called when you click the canvas
        }
    };

    @Override
    public void onStart() {
        getBot().addMouseListener(mouseListener);
    }

    @Override
    public int onLoop() throws InterruptedException {
        // generate a mouse event
        getBot().getMouseEventHandler().generateBotMouseEvent(...);
        return 1000;
    }

    @Override
    public void onExit() throws InterruptedException {
        getBot().removeMouseListener(mouseListener);
    }
}

https://osbot.org/api/org/osbot/rs07/input/mouse/ClientMouseEventHandler.html

Posted
20 hours ago, Camaro said:

BotMouseListener is a class than can be used to record your mouse clicks. In order to recreate them, use the ClientMouseEventHandler


import org.osbot.rs07.input.mouse.BotMouseListener;
import org.osbot.rs07.script.Script;

import java.awt.event.MouseEvent;

public class MouseHandler extends Script {

    private final BotMouseListener mouseListener = new BotMouseListener() {
        @Override
        public void checkMouseEvent(MouseEvent mouseEvent) {
            // called when you click the canvas
        }
    };

    @Override
    public void onStart() {
        getBot().addMouseListener(mouseListener);
    }

    @Override
    public int onLoop() throws InterruptedException {
        // generate a mouse event
        getBot().getMouseEventHandler().generateBotMouseEvent(...);
        return 1000;
    }

    @Override
    public void onExit() throws InterruptedException {
        getBot().removeMouseListener(mouseListener);
    }
}

https://osbot.org/api/org/osbot/rs07/input/mouse/ClientMouseEventHandler.html

Thank you so much, works like a charm.

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...