Jump to content

Adding In A Mouse Listener


Joseph

Recommended Posts

Before in OSBot 1 they had mouse listener already implemented but in OSBot 2 you have to initialize it yourself. How do you go about doing that.

 

Please be aware that within the bot class there's a method called addMouseListener. Which allows you to add in your moue listener. The methods constructor supports (java MouseListener) but since osbot has a class called BotMouseListener that extends the (java MouseListener). if you know anything about OOP, youll know that you allowed to use java Mouse Listener or OSBot listener. I highly suggest using the OBSot Mouse Listener. Just because it contains an extra method.

java.awt.event.MouseListener

Step one: Within the onstart you would have 

	@Override
	public void onStart() throws InterruptedException {
		this.bot.addMouseListener(new BotMouseListener() {

			@Override
			public void mouseClicked(MouseEvent e) {}

			@Override
			public void mouseEntered(MouseEvent e) {}

			@Override
			public void mouseExited(MouseEvent e) {}

			@Override
			public void mousePressed(MouseEvent e) {}

			@Override
			public void mouseReleased(MouseEvent e) {}

			@Override
			public boolean blockInput(Point arg0) {
				return false;
			}
		});			
	}

 pretty much your done  ^^^^

 

What could you do with this? you could do many thing its up to you. But mainly people use it to hide/show their paints.

 

Code example:

Rectangle rec = new Rectangle(0,0,0,0);
boolean hidePaint = false;	
//with in the onPaint you would use the hidePaint boolean to determine if you should paint your info or not.

	@Override
	public void onStart() throws InterruptedException {
		this.bot.addMouseListener(new BotMouseListener() {

			@Override
			public void mouseClicked(MouseEvent e) {
				Point point = e.getPoint(); //return the current point of the mouse
				
				if (rec.contains(point))
					hidePaint = !hidePaint;	//this inverts the boolean
			}

			@Override
			public void mouseEntered(MouseEvent e) {}

			@Override
			public void mouseExited(MouseEvent e) {}

			@Override
			public void mousePressed(MouseEvent e) {}

			@Override
			public void mouseReleased(MouseEvent e) {}

			@Override
			public boolean blockInput(Point arg0) {
				return false;
			}
		});			
	}

 

PS. Someone PMed me asking me how to do it. I Explained to him/her how it was done. Decided to release it to the community for the one that are still learning :D

Edited by josedpay
  • Like 1
Link to comment
Share on other sites

An easier way would just be to implement the class. This way you can create your own listener class which handles the overrides and keep your project organized.

ofc but i thought this would be easier for the newbies. i mean newbies don't know much about oop (or so i think). But thanks for the input biggrin.png

 

question whats better having you main script implement the Bot mouse listener. Or creating your own listener that implements the bot mouse listener?

Edited by josedpay
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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