PDA

View Full Version : Making a mouse movement



Infantry001
11-07-2006, 06:54 PM
How should i go about making a mouse movement? If you could list steps, i would be thankful. Please no "Use math combined with movemousesmoothex", cuz that doesnt help at all lol.

Boreas
11-07-2006, 07:09 PM
I'm not sure what you mean. If you mean move the mouse to some point then use mmouse

From MouseFlag.scar


{************************************************* ******************************
function MMouse(dx, dy, RandX, RandY: Integer): Boolean;
By: BenLand100/Mutant Squirrle
Description: Moves the mouse along a spline to (dx, dy) with an ending randomness of RandX and RandY (If BenMouse=True (Default))
Global var BenMouse determines the behaviour of MMouse.
If an error occures the return value is false insted of crashing your script
************************************************** *****************************}

If not, please explain again.

Infantry001
11-07-2006, 07:41 PM
i mean i want to create a mouse movement

Boreas
11-07-2006, 07:49 PM
Like this?


{Sine wave, use in paint with pencil}

Program New;
{.include SRL/SRL.scar}

Type
CoArray = Record
x, y : Integer;

End;


Function MakePath() : Array Of CoArray;

Var
NArray : Array Of CoArray;
i : Integer;

Begin
i := 0;

SetArrayLength(NArray, 100);

Repeat

NArray[i].x := i*15 + Random(10);
NArray[i].y := Round(Sin((i/2)*1) *50) + Random(1);

i := i + 1;

Until(i =40)



Result := NArray;

End;



Var
myarray : Array of CoArray;
i : Integer;

Begin

SetupSRL;

SetArrayLength(myarray, 100000)
//mousespeed:=30;
myarray := MakePath();

MMouse(50, 200, 0, 0);
holdmouse(50,200,true);
Sleep(10) Repeat
//repeat
// wait(4);
//until isfkeydown(11);
MMouse(myarray[i].x + 50, myarray[i].y + 200, 0, 0);
i := i + 1;
Sleep(5);

Until((i = 40) or isfkeydown(12)) ;
getmousepos(x,y);
releasemouse(x,y,true);



End.


Like making a certain shaped path?

Infantry001
11-07-2006, 08:04 PM
yea.
also, can you explain to me what sin and cos are, cuz im only in geometry lol and i also want to make a spline path, like BenLand.

Boreas
11-07-2006, 08:29 PM
Ahh I see. Think of sin and cos are like formulas that relate parts of a triangle. Don't worry about that though. In the example above sin is used purely for the wavy shape it's graph makes.

Quick graphing/geometry tutorial:

On a regular coordinate plane (not the one we use), the equation y=x looks like a diagonal line. When x is 1, y is 1, when x is 2, y is 2. As x increases going along to the right, y increases excatly the same going up. This makes a diagonal line. We can change how this line looks by changing the equation.

For example, y=2x. Now when x is 1, y is 2, when x is 2, y is 4. This means that x increases along to the right, y increase twice as much going up, thereby making a steeper line.

Another example is y=2x+3. When x is 1, y is 5, when x is 2, y is 7. Pick some values for x, figure out what y is, and plot the points. It's just as steep as the last example, but moved up 3.

Now y=sin(x) looks like a wave. That means as x goes along to the right, y goes up and down and up....etc. We can manipulate just like before. I changed values in the code above to change how wide and tall the wave looks. (I also added randomness)

So to make a mouse movement, you first have to figure out what shape you want it to follow. Then figure out the formula for that. For example if you want it to make a U kind of thing you can use a hyperbola, and manipulate it to be upsidedown, sideways, wider etc.

The next step is to make a path from the formula. Mmouse uses benland100's makesplinepath which takes the path and breaks it up into little pieces, and the above code uses make path. If you think about it, a line is really a bunch of points. If you take an octagon, and keep increasing the number of sides, eventually it will look like a smooth circle, but if you look close you can see lots of tiny lines. Making a path does the same thing, it makes a bunch of points (in an array) on the line, and joins them together with little lines. The mouse moves from one point to the next, thereby putting the little lines together into a path.

Now the bunch of points in the array each have x and y that fit into the formula. You increase x by a little bit and find the y to match it with the forumla to create the point. If you have more points and increase the x by a smaller amount, there will be more little lines that are smaller, so it will look smoother. For example, the code above was modified from something that solarwind made that had less points, and so the wave looked more pointy.


This sounds quite complicated, but really all you have to do is figure out the formula of the path you want and stick it where the sin is in the above code. Figuring out the formula is the hard part. I've been trying to figure one out for an adjustable figure 8, it's driving me nuts!

What kind of path are you thinking about?

Infantry001
11-07-2006, 08:45 PM
i want circular paths, cuz whenever i am playin legit and i am waiting for a rock to get mined or something, i circle my mouse

and btw, thanks a lot! rep++ :D

Boreas
11-07-2006, 10:22 PM
Np:D .

Ok circle is a little different because you can't just have an x and then as it increase the y changes because a circle has 2 y's for each x and 2 x's for each y (besides the very top, very left, very bottom and very right). What you can do is use degrees or radians. Don't worry about radians for now, lets just say it's like another way of measuring angles. Anyway, a circle has degrees that go from 0 to 360, so we can use that. This is the way we can divide up the path in to lots of points. Now imagine the circle like a pie or cake or pizza, divide into 4 equal pieces. Each piece has a curved line, and 2 straight lines that join at an angle, that angle is 90 degress, which is 360 divided by 4. Now these curved lines are the little lines I talked about before, and the places on the circumference is where the points are. This only has four points, and would end up looking like a diamond if you joined the points. Now if you cut each piece in half again you get 8 points with 8 lines between, with each angle being 360/8=45. If you joined these points together you would get an octogan. More pieces means, more points, more lines, smoother look and smaller angles. You could divide into 360 pieces having angle of 1 degree, or 720 with half a degree, or 180 with 2. Lets do 360 as an example.

Number of degrees will be what we work from because everything else depends on it (where as x was before). We have 360 points, and we increase the number of degrees by 1 to go from one point to the next. Lets imagine that 0 degrees is like 12 on a clock, 90 is 3, 180 is 6, 270 is 9. Now the bunch of points that make up the path all lie on the circumference. We need the coordinates of each point.

To make this simple, lets get the coordinates of the first point in relation to the center of the circle. Get some paper and draw this.

Draw a circle. Draw a lince from the center to '12 o clock'. Draw another line from the center to '1 o clock'. The angle between these 2 lines is actually 360/12, but just pretend it's 1 because drawing an angle of 1 degree would like the pencil lines on top of each other. Now the point where the '1 o clock line' hits the circuference of the circle is the point we want. We want to find the difference in x position to the center point, and the same for y. To do this we will right angle trigonometry. It's not as bad as it sounds. From the '1 o clock point', draw a horizontal line to the vertical '12 line'. You should now have a triangle, with a horizontal line across the top, a vertical line on the left (12 line) and a diagnoal line (radius).

We know the length of the radius (because you would tell the mouse procedure how big the circle is) lets say it's 10. We know the angle in the center (it's about 30 but pretend its 1). We don't know the length of the other 2 lines in the triangle, these are the differences in x and y positions of the center point and the point on the path. We will use sin and cos to find this out. These two lines meet at a right angle, 90 degrees, this is good because we need one of the angle to be 90 for the following to work.

Remember this: Soh Cah Toa
S=O/H C=A/H T=O/A
Sin(x)=Opposite/Hypoteneus Cos(x)=adjacent/hypoteneuse Dont worry about the other one.

Sin(x) means sin of the angle. You put in the angle at the center, and it returns a value.
Hypoteneuse is the line that doesn't touch the right angle (the radius in this case).
Opposite is the side that doesn't touch the angle we put in for x.
Adjacent is the side that does touch the angle we put in for x.

Lets figure out the horizontal line. That would be the opposite because it doesn't touch the center angle. Hypoteneuse is the radius (calling it 10). x is the angle (1). So we get

Sin(1)=?/10

Sin(1)*10=?

So the length of the horizontal line is sin(1)*10. So the x coord of the point is sin(1)*10 plus the x coord of the center.

The same thing applies for the vertical line to get the y, except you want the adjacent line so you use cos instead of sin. Now you have your first point. You would then repeat this with the next angle and so and so on, until you have 360 points in an array. Then you move from one to the next to follow the path of the circle.

Things to think about is what happens when you go from you quadrant to the next, and that the coordinate plane for scar works differently (increase to the right and down).

This may be tough to understand if you haven't taken certain math classes, plus I rushed this and didn't explain some things thoroughly, so feel free to ask questions. I may write a procedure to demonstrate this later. Otherwise, I and others can help you along the way.

Infantry001
11-07-2006, 11:47 PM
thanks, man. ur great! one more thing i want to learn how to do is actually make a spline path that the mouse moves along, but you can take your time. You have already helped me a lot!

Boreas
11-08-2006, 01:50 AM
If you're talking about making a path for the circle thing, then the code above will do if you change

NArray[i].x :=
NArray[i].y :=
so that i is the number of degrees, and the x and y are figured out with the trig stuff I was talking about. Also add a paramter for radius, and change the array length etc.

If you're talking about doing something like benland100's makesplinepath then I would suggest trying something easier first because that's one of his greatest achievements and he has one of the highest IQs here.

Pyro
11-08-2006, 02:43 AM
To be totally truthful. Im not being mean or anything remotely close to it. But i suggest not trying to make a mouse path function. If you havnt studied cos and sin well. Even if you still use it for triangles its the year after you learn that that you learn all there is to do with maths.

Infantry001
11-08-2006, 02:47 AM
heh i learn fast enough :D

but if i encounter any trouble, i will know i dont have the knowledge yet. btw, what class do you learn sin and cos in?

IronTeapot
11-08-2006, 03:01 AM
I think i learned it in grade 10 basic math? the unit where you learn about triangles and sin cos and tan, and the sine law and cosine law, and just a bunch of triangles. It was basic math class though, nothing fancy.

Infantry001
11-08-2006, 03:08 AM
yea im only in geometry, i think i might learn either this year or next year.

IronTeapot
11-08-2006, 03:10 AM
I think its part of the geometry class.... Its to do with geometrics of triangles anyways. If you want to learn about sine waves ( how bens mouse was made) then have a look here.
http://en.wikipedia.org/wiki/Sine_wave

Infantry001
11-08-2006, 03:17 AM
eh ill take a look in my textbook :P

Boreas
11-08-2006, 03:42 AM
I first learnt what Iron said in his first post in grade 10 (year 11 for UK) geometry, it was just thrown on the end. Then trigonometry(half year class) in 11(12) went into more detail.

As Pyro and I said before, this is tricky stuff, even if you have learnt it in school, because it's a different application than usual (I'm going on what I used it for geo/trig/physics classes in high school). There's a reason you don't see a lot of these around.

I'll make you a deal, if I can crank out a half decent circle thing in a couple hours (and I'm a big math nerd) probably tommorow, go ahead with it. If not, I would suggest trying something else that uses existing mouse stuff creatively to simulate your movement while waiting for a rock.

EDIT: Just made this, run on paint with pencil.

Now hold down the mouse button and move your and in a circle a few times like you would while waiting for rocks. It looks nothing like it. Infact its more of an ellipse that had too many tequilas. Meh, IMHO this isn't really worth pursuing for moving mouse while bored type deals. I may use it for moving mouse while checking uptext with 1 or 2 rotations, but that's about it. Meh, go for it if you want, but it's a long way from how I move the mouse.


{draws circle, set target on paint, put mouse above paint, press f9 to start f12 to stop

}
Program New;
{.include SRL/SRL.scar}

Type
CoArray = Record
x, y : Integer;

End;

const r=50; //radius
randy=1; //1 for randomness, 51 for none


Function MakePath(radius:integer) : Array Of CoArray;

Var
NArray : Array Of CoArray;
i ,rany,ranx,ranradx,ranrady: Integer;

Begin
i :=0;

SetArrayLength(NArray, 361);

Repeat
if random(50)=randy then
rany:=random(3);

if random(50)=randy then
ranx:=random(3);
ranradx:=radius;
if random(50)=randy then
ranradx:= ((radius-1)+random(1));
ranrady:=radius;
if random(50)=randy then
ranrady:= ((radius-1)+random(1));
i := i + 1;

NArray[i].y := round(sin(radians(i))*ranrady)+rany;
NArray[i].x := round(cos(radians(i))*ranradx)+ranx;



Until(i =360)



Result := NArray;

End;



Var
myarray : Array of CoArray;
i : Integer;

Begin

SetupSRL;

SetArrayLength(myarray, 100000)
//mousespeed:=30;

getmousepos(x,y);
mouse(x,y,0,0,true);

mmouse(x+r,y,0,0)
holdmouse(x+r,y,true);
repeat
i:=0;Sleep(10)
myarray := MakePath(r);
Repeat
//repeat
// wait(4);
//until isfkeydown(11);


i := i + 1;
MMouse(myarray[i].x + x, myarray[i].y + y, 0, 0);

Sleep(3);

Until((i = 360) or isfkeydown(12)) ;
until isfkeydown(12);
getmousepos(x,y);
releasemouse(x,y,true);



End.

Pyro
11-08-2006, 05:28 AM
I learnt sine and cos WAVES in my second to last year at school. And for triangles i learnt it one year before. Actually the more i think about it the more a sine and cosine waves eem logical. Just adding co effiecents everywhere slightly to make it random. hm i may try it out.

Boreas
11-08-2006, 05:46 AM
I learnt sine and cos WAVES in my second to last year at school. And for triangles i learnt it one year before. Actually the more i think about it the more a sine and cosine waves eem logical. Just adding co effiecents everywhere slightly to make it random. hm i may try it out.

Let me know how it goes. I played with the script in my second post and it was either too much so that it looked erractic and not smooth human movement, or it still looked like a sine wave. Increasing the number of points and decreasing the distance between them helped somewhat, but even when the points were random the general path looked too perfect to be human. Well it may not get detected by an algorithm, but it didn't look close to when I tried to make a wave by hand.

lardmaster
11-08-2006, 09:18 PM
wow, this sounds like he wants to make EXACTLY what i have made and posted on these forums, look for lardmasters uberbored mouse or lardmasters mouse, and you will see.

about sin and cos, you dont truly understand everything about them until trig, which is 11 grade advanced math or 12 grade math, in the USA. some schools dont have advanced math...
think of cos as the x coord as you go around the edge of a circle with a radius of one counterclockwise starting facing right, and sin is the y coordinate

personally, something that does an exact path is ok to make on your own, but you shouldnt try to reinvent mmouse.

Infantry001
11-08-2006, 10:33 PM
Well, im learning Sine and Cosine theories this year, but for triangles (ps: im in 8th grade :P), so i think i would probably learn the waves in 10th grade yay! I saw how they are used in my textbook, and im like "whaaaaat???" lol.

@lardmaster: ill take a look :D

Boreas
11-09-2006, 12:30 AM
You'll probably use the triangle more often (like in the circle thing and geometry) than the actual wave shape (like in the first code I posted and physics.

Infantry001
11-09-2006, 01:09 AM
heh good :D

lardmaster
11-09-2006, 02:26 AM
yeah, you learn about it in triangles in 9(10)? grade based on how u r doing. im a little confused about it because i am 2 years ahead in math, and then theres advanced math and crap like that so... you should know a little about it by the end of the year if you are in eighth. :P

i hope you like my boredmouse, you can do anything to it that you want...