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
  • Catching mouse events from user


    arowar
     Share

    Recommended Posts

    Hey fellow scripters

    I'm trying to catch mouseevents from the user while a script is running but my mouselistener seems to only catch events from the mousepointer that is used ingame (i.e. the mousepointer my script uses).
    I'm trying to make an interactive paint that can change state when a user clicks on a graphic without interrupting my script.

    Any ideas?

    Link to comment
    Share on other sites

     

     

    I may have missed something, but here's an example to toggle your paint, you can use this to work out how an interaction works

     

    /* In your main class
     * Use IDE to implement the methods
     * Here is an example for toggling your paint without interrupting the script
     */
    
    public class main extends AbstractScript implements MouseListener {
    
    private Boolean hidePaint = false;
    private Rectangle rect = new Rectangle(504, 340, 15, 15);
    private Rectangle closePaint = rect;
    private Rectangle openPaint = rect;
    private point p;
    
    // In your onPaint()
    
    public void onPaint(Graphics g) {
    	if (!hidePaint) {
    // Code to show your paint
    	} else {
    // Code to show another custom image which doesn't cover chat
    	}
    }
    
    @Override
    public void mouseClicked(MouseEvent e) {
      
        p = e.getPoint();
      
        if (closePaint.contains(p) && !hidePaint) {
    
            hidePaint = true;
    
        } else if (openPaint.contains(p) && hidePaint) {
    
            hidePaint = false;
        } 
    }	
    
    @Override
    public void mousePressed(MouseEvent e) {
    
    }
    
    @Override
    public void mouseReleased(MouseEvent e) {
    
    }
    
    @Override
    public void mouseEntered(MouseEvent e) {
    
    }
    
    @Override
    public void mouseExited(MouseEvent e) {
    
    }
    }
    Edited by Xtra
    Link to comment
    Share on other sites

    i've implemented this in a similar way but i don't get an event when the script is running (user input is disabled)

    p = new ExtenderPainter(hm);  //extends MouseListener
            main.getClient().getInstance().addEventListener(p);
    
    
    --
    
    
    //in ExtenderPainter
    @Override
        public void mouseClicked(MouseEvent e) {
            hm.log("event fired");
            PainterPane clickedPane = panes.stream().filter(p -> p.containsPoint(e.getPoint())).findFirst().orElse(null);
            if(clickedPane != null) {
                clickedPane.open();
            }
        }

    I only get this log message when I enable user input (interfering with the script)

     

     

    Edited by arowar
    Link to comment
    Share on other sites

    I assume the mouse listeners only detects the mouse events when the mouse interacts with the game canvas (which doesn't occur when user input is disabled)

    Edited by Pseudo
    Stupid mobile autocorrect
    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.