Sythe.Org Forums     Register     FAQ     Members List     Calendar     Mark Forums Read    
 
Sythe.Org Forums  
   Runescape Gold

Sythe.org — A Virtual Goods Trading Hub

Make real cash! buying and selling in-game items.

We have a no-scam policy.

You can make thousands playing your favourite games here at Sythe.org.

Just sign up an account and follow the rules!


Take me to

Runescape Markets

Other Game Markets

Support Center

Register an Account

Close
moveMouseSmooth()
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 06-03-2010, 01:41 PM
Blupig's Avatar
i am a guy ok?? -.-
Ex-Moderator Zombie Visual Basic Programmers
 
Join Date: Nov 2006
Location: Canada
Posts: 5,232
Send a message via MSN to Blupig Send a message via Skype™ to Blupig
MushyMuncher
Default moveMouseSmooth()

Fully commented etc, please credit if you use it. You'll have to make your own error handing.

Code:
public static void moveMouseSmooth(int sx, int sy, int steps){
		
		//Try the following code
		try{
		
			//Create a new robot object called mouseBot
			Robot mouseBot = new Robot();
			
			//Get current X and Y coordinates of the mouse
			//X
			int currX = MouseInfo.getPointerInfo().getLocation().x;
			//Y
			int currY = MouseInfo.getPointerInfo().getLocation().y;
			
			//Get the difference between the desired coordinates and 
			//			the current coordinates, then make sure the result is positive
			//X
			int diffX = Math.abs(sx - currX);
			//Y
			int diffY = Math.abs(sy - currY);
			
			//Calculate the interval at which to add to the coordinates as
			//			the code cycles through, then round off the division
			//X interval
			int intervalX = Math.round(diffX/steps);
			//Y interval
			int intervalY = Math.round(diffY/steps);
			
			
			//As long as the number of steps is bigger than or equal to i, do the code
			//			and add 1 onto i each time (counter)
			for(int i = 0; i <= steps; i++){
				
				//Make the application's current thread sleep for 10 ms
				//This is so that the mouse doesn't move super fast, but doesn't lag
				Thread.sleep(10);

				//"Teleport" the mouse to the current X and Y coordinates
				mouseBot.mouseMove(currX, currY);
				//Remake the current X and Y coordinates by adding the interval
				//These new coordinates are the future destinations of the mouse cursor
				//X
				currX = currX + intervalX;
				//Y
				currY = currY + intervalY;
			
			}
			
			//To eliminate any inaccuracy, "teleport" the cursor to the final position
			mouseBot.mouseMove(sx, sy);
			//Print that it was successful
			consolePrint("[mouse.smoothXY(point, int)]  mouse moved succesfully to (" + sx + ", " + sy + ")");
			
		//Catch any object errors
		} catch (AWTException e){
			
	
			
		//If the thread sleeping was interrupted...
		} catch (InterruptedException e2){

			
		}
		
	}
Don't comment on me using sleep either, for what I needed this for that was fine.
__________________
Reply With Quote
  #2  
Old 06-11-2010, 03:05 AM
Member
 
Join Date: Dec 2008
Posts: 91
Default Re: moveMouseSmooth()

not even going to use a spline? only basic linear interpolation?
Reply With Quote
Reply



Cheap RS Gold Store  Runescape Gold

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT +1. The time now is 01:57 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.6.1