Jump to content
dc0qdguZU8R50JJu

BotMouseListener: checkMouseEvent. Trying to register mouse events.

Recommended Posts

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!

Link to post
Share on other sites

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

Link to post
Share on other sites
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
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...