lacergunn 2 Share Posted January 30, 2021 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 More sharing options...
Gorn 4 Share Posted January 30, 2021 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 More sharing options...
lacergunn 2 Author Share Posted January 30, 2021 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 More sharing options...
Gorn 4 Share Posted January 31, 2021 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) 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 More sharing options...
Gorn 4 Share Posted January 31, 2021 and by that cunt I mean the quote, not you Link to comment Share on other sites More sharing options...
lacergunn 2 Author Share Posted February 2, 2021 On 1/31/2021 at 5:55 AM, Gorn said: and by that cunt I mean the quote, not you I figured, otherwise there would have been a comma Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.