@@ -108,7 +108,7 @@ void updateScreenMetrics()
108108 * Move the mouse to a specific point.
109109 * @param point The coordinates to move the mouse to (x, y).
110110 */
111- void moveMouse (MMSignedPoint point )
111+ void moveMouse (MMSignedPoint point , bool sm )
112112{
113113#if defined(IS_MACOSX )
114114 CGEventRef move = CGEventCreateMouseEvent (NULL , kCGEventMouseMoved ,
@@ -128,13 +128,20 @@ void moveMouse(MMSignedPoint point)
128128
129129 if (vscreenWidth < 0 || vscreenHeight < 0 )
130130 updateScreenMetrics ();
131-
132- //Mouse motion is now done using SendInput with MOUSEINPUT. We use Absolute mouse positioning
133- #define MOUSE_COORD_TO_ABS (coord , width_or_height ) ((65536 * (coord) / width_or_height) + ((coord) < 0 ? -1 : 1))
134-
135- size_t x = MOUSE_COORD_TO_ABS (point .x - vscreenMinX , vscreenWidth );
136- size_t y = MOUSE_COORD_TO_ABS (point .y - vscreenMinY , vscreenHeight );
137-
131+ int32_t x = 0 ;
132+ int32_t y = 0 ;
133+ if (!sm )
134+ {
135+ //Mouse motion is now done using SendInput with MOUSEINPUT. We use Absolute mouse positioning
136+ #define MOUSE_COORD_TO_ABS (coord , width_or_height ) ((65536 * (coord) / width_or_height) + ((coord) < 0 ? -1 : 1))
137+
138+ x = MOUSE_COORD_TO_ABS (point .x - vscreenMinX , vscreenWidth );
139+ y = MOUSE_COORD_TO_ABS (point .y - vscreenMinY , vscreenHeight );
140+ }
141+ else {
142+ x = point .x ;
143+ y = point .y ;
144+ }
138145 INPUT mouseInput = {0 };
139146 mouseInput .type = INPUT_MOUSE ;
140147 mouseInput .mi .dx = x ;
@@ -158,11 +165,11 @@ void dragMouse(MMSignedPoint point, const MMMouseButton button)
158165 CGEventPost (kCGSessionEventTap , drag );
159166 CFRelease (drag );
160167#else
161- moveMouse (point );
168+ moveMouse (point ,false );
162169#endif
163170}
164171
165- MMPoint getMousePos ()
172+ MMSignedPoint getMousePos ()
166173{
167174#if defined(IS_MACOSX )
168175 CGEventRef event = CGEventCreate (NULL );
@@ -184,8 +191,13 @@ MMPoint getMousePos()
184191#elif defined(IS_WINDOWS )
185192 POINT point ;
186193 GetCursorPos (& point );
194+ if (vscreenWidth < 0 || vscreenHeight < 0 )
195+ updateScreenMetrics ();
196+ #define MOUSE_COORD_TO_ABS (coord , width_or_height ) ((65536 * (coord) / width_or_height) + ((coord) < 0 ? -1 : 1))
187197
188- return MMPointFromPOINT (point );
198+ int32_t x = MOUSE_COORD_TO_ABS (point .x - vscreenMinX , vscreenWidth );
199+ int32_t y = MOUSE_COORD_TO_ABS (point .y - vscreenMinY , vscreenHeight );
200+ return MMSignedPointFromPOINT (point );
189201#endif
190202}
191203
@@ -370,15 +382,18 @@ static double crude_hypot(double x, double y)
370382 return ((M_SQRT2 - 1.0 ) * small ) + big ;
371383}
372384
373- bool smoothlyMoveMouse (MMPoint endPoint ,double speed )
385+ bool smoothlyMoveMouse (MMPoint endPoint , double speed )
374386{
375- MMPoint pos = getMousePos ();
376- MMSize screenSize = getMainDisplaySize ();
387+ MMSignedPoint pos = getMousePos ();
388+ MMSignedSize screenSize = getMainDisplaySize ();
377389 double velo_x = 0.0 , velo_y = 0.0 ;
378390 double distance ;
379-
391+ int32_t x , y = 0 ;
392+ if (vscreenWidth < 0 || vscreenHeight < 0 )
393+ updateScreenMetrics ();
394+ double bdist = (distance = crude_hypot ((double )pos .x - endPoint .x ,(double )pos .y - endPoint .y ));
380395 while ((distance = crude_hypot ((double )pos .x - endPoint .x ,
381- (double )pos .y - endPoint .y )) > 1.0 ) {
396+ (double )pos .y - endPoint .y )) > 1.0 ) {
382397 double gravity = DEADBEEF_UNIFORM (5.0 , 500.0 );
383398 double veloDistance ;
384399 velo_x += (gravity * ((double )endPoint .x - pos .x )) / distance ;
@@ -397,11 +412,14 @@ bool smoothlyMoveMouse(MMPoint endPoint,double speed)
397412 if (pos .x >= screenSize .width || pos .y >= screenSize .height ) {
398413 return false;
399414 }
415+ #define MOUSE_COORD_TO_ABS (coord , width_or_height ) ((65536 * (coord) / width_or_height) + ((coord) < 0 ? -1 : 1))
400416
401- moveMouse (MMSignedPointMake ((int32_t )pos .x , (int32_t )pos .y ));
417+ x = MOUSE_COORD_TO_ABS (pos .x - vscreenMinX , vscreenWidth );
418+ y = MOUSE_COORD_TO_ABS (pos .y - vscreenMinY , vscreenHeight );
419+ moveMouse (MMSignedPointMake (x ,y ),true);
402420
403421 /* Wait 1 - (speed) milliseconds. */
404- microsleep (DEADBEEF_UNIFORM (0.7 , speed ));
422+ microsleep (DEADBEEF_UNIFORM (( min ( 0.7 ,speed ) + ( 1 - ( distance / (( bdist + 0.0001 ) * 2 )))), ( max ( 0.7 , speed ) - ( distance / (( bdist + 0.0001 ) * 1.5 ))) ));
405423 }
406424
407425 return true;
0 commit comments