Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • Recording mouse inputs?


    lacergunn
     Share

    Recommended Posts

    I'm trying to write a multiboxer, but I can't figure out how to record where the main user is clicking, and whether or not it's a left click or right click. Right now I've been using the crosshair status as my indicator, but that only works when left clicking in the main window, and doesn't do anything for clicking in menus or clicking on the minimap

    Link to comment
    Share on other sites

    So what exactly do you have a problem with, getting the position or just the mouse click?

    Either way you have to implement MouseListener

    Link to comment
    Share on other sites

    2 hours ago, Gorn said:

    So what exactly do you have a problem with, getting the position or just the mouse click?

    Either way you have to implement MouseListener

    mainly the click, I have the position

    Link to comment
    Share on other sites

    I was working on something related when I tried to make a whole bot that would only use mouse recordings

    Spoiler

    protip: It's not a good idea

    I assume you are relatively new programmer if you are asking about this crap and I feel like writing a tut so here it is step by step:

    first create a function that implements MouseListener

    MyMouseListener.java

    
    public class MyMouseListener implements MouseListener{
    
    }

    now the IDE shoud shoud give you a prompt to add the other methods ("implement the interface" if you want to be technical about it, MouseListener is the interface meaning all it's methods are abstract (they are  empty) so you have to implement them)

    Interface.png.14d777d81943f63975dbdd095365f136.png

    You probabaly want this to communicate with some other class, this completely depends on how your program is structured. Let's say we have a class called Manager that will 'handle' this 'event' (the mouse click). So let's create a constructor in the listener with the manager as a parameter so we can call functions from it.

    MyMouseListener.java

    	Manager m;
    	
    	MyMouseListener(Manager manager){
    		m = manager;
    	}

    This means you will have to instantiate the listener in the manager. The manager will then pass itself as an argument into the constructor (that's what the 'this' means) so that the listener has a refrence to it. We also have to register the listener with the client.

    Manager.java

    	MyMouseListener mouseListener;
    	
    	@Override
    	public void onStart() {
    		mouseListener = new MyMouseListener(this);
    		Client.getInstance().addEventListener(mouseListener);
    	}

    Now let's actually implement the mousePressed method (mousePressed because mouseClicked only fires after the mouse was also released while the game will take the click right after you press the mouse).

    MyMouseListener.java

    	@Override
    	public void mousePressed(MouseEvent e) {
    		switch(e.getButton()) {
    		case MouseEvent.BUTTON1:
    			m.doStuffOnLeftClick();
    			break;
    		case MouseEvent.BUTTON3:
    			m.doStuffOnRightClick();
    			break;
    		}
    	}

    now you can implement your own methods in the manager

    Manager.java

    	public void doStuffOnLeftClick() {
    		MethodProvider.log("left click");
    	}
    	
    	public void doStuffOnRightClick() {
    		MethodProvider.log("right click");
    	}

    and that's it! Actually it's not... honestly it wouldn't be programming without some good old bullshit or bugs. I don't think there is a way currently to remove the mouse listener (since this was already asked here and nobody responded) so if you stop the script and start it again the old listener is still there and it will fire twice. You would have to close Dreambot and open it again so that it would fire only once again. I was thinking about it for a moment and I already have quick fix for that, but I will let you figure that one out yourself, can't take that away from you.

    Senpai @Neffarion made a guide here on custom listeners. You can create events for other things, not just mouse buttons. This style of programming is called the 'Observer pattern' and I feel like a lot of more experienced programmers like it. I remember adding, I think it was AdMob, into one game and it was all written as events and listeners. So understanding this could come in handy later when you work on something else, or try to get a job as programmer or nonsense like that.

    Anyway here is some poetry on the whole 'Listener - Event - Handler' terminology I found on SO.

    Quote

    "I think the difference is subtle because a concrete Listener is an event-handler too or at least has a method that can be considered an event-handler. That is, a concrete Listener handles or manages the reaction to the event after receiving an event object(from the event-source) with all the usefull informations about the event just occurred(on the event-source). As this Listener has to implement an xxxListener interface that forces him to implement at least one method that is in turn executed by the event-source object when the event occurs, so the Listener itself can be considered an handler and more precisely, the method of the Listener interface implemented by the Listener object can be considered the real event-handler. So i view the event-handler as just the code that is executed in reaction to an event. This is different from a Listener object that is an element of a more abstract concept such as an Observer design pattern. This is my personal view of the subject." - Stackoverflow

    Yeah, try to parse that cunt

    Link to comment
    Share on other sites

    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
     Share

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.