diff --git a/mouse/mouse_c.h b/mouse/mouse_c.h index 18fe1ae..5b8ed5d 100644 --- a/mouse/mouse_c.h +++ b/mouse/mouse_c.h @@ -310,7 +310,8 @@ static double crude_hypot(double x, double y){ return ((M_SQRT2 - 1.0) * small) + big; } -bool smoothlyMoveMouse(MMPointInt32 endPoint, double lowSpeed, double highSpeed){ +static bool smoothlyMoveMouseImpl(MMPointInt32 endPoint, double lowSpeed, double highSpeed, + bool drag, MMMouseButton button){ MMPointInt32 pos = location(); // MMSizeInt32 screenSize = getMainDisplaySize(); double velo_x = 0.0, velo_y = 0.0; @@ -335,7 +336,11 @@ bool smoothlyMoveMouse(MMPointInt32 endPoint, double lowSpeed, double highSpeed) // if (pos.x >= screenSize.w || pos.y >= screenSize.h) { // return false; // } - moveMouse(pos); + if (drag) { + dragMouse(pos, button); + } else { + moveMouse(pos); + } /* Wait 1 - 3 milliseconds. */ microsleep(DEADBEEF_UNIFORM(lowSpeed, highSpeed)); @@ -343,3 +348,12 @@ bool smoothlyMoveMouse(MMPointInt32 endPoint, double lowSpeed, double highSpeed) } return true; } + +bool smoothlyMoveMouse(MMPointInt32 endPoint, double lowSpeed, double highSpeed){ + return smoothlyMoveMouseImpl(endPoint, lowSpeed, highSpeed, false, LEFT_BUTTON); +} + +bool smoothlyDragMouse(MMPointInt32 endPoint, double lowSpeed, double highSpeed, + MMMouseButton button){ + return smoothlyMoveMouseImpl(endPoint, lowSpeed, highSpeed, true, button); +} diff --git a/robotgo.go b/robotgo.go index 607c828..168d322 100644 --- a/robotgo.go +++ b/robotgo.go @@ -578,24 +578,11 @@ func Drag(x, y int, args ...string) { func DragSmooth(x, y int, args ...interface{}) { Toggle("left") MilliSleep(50) - MoveSmooth(x, y, args...) + smoothMove(x, y, true, args...) Toggle("left", "up") } -// MoveSmooth move the mouse smooth, -// moves mouse to x, y human like, with the mouse button up. -// -// robotgo.MoveSmooth(x, y int, low, high float64, mouseDelay int) -// -// Examples: -// -// robotgo.MoveSmooth(10, 10) -// robotgo.MoveSmooth(10, 10, 1.0, 2.0) -func MoveSmooth(x, y int, args ...interface{}) bool { - // if runtime.GOOS == "windows" { - // f := ScaleF() - // x, y = Scaled0(x, f), Scaled0(y, f) - // } +func smoothMove(x, y int, drag bool, args ...interface{}) bool { x, y = MoveScale(x, y) cx := C.int32_t(x) @@ -619,12 +606,30 @@ func MoveSmooth(x, y int, args ...interface{}) bool { high = 3.0 } - cbool := C.smoothlyMoveMouse(C.MMPointInt32Make(cx, cy), low, high) + var cbool C.bool + if drag { + cbool = C.smoothlyDragMouse(C.MMPointInt32Make(cx, cy), low, high, C.LEFT_BUTTON) + } else { + cbool = C.smoothlyMoveMouse(C.MMPointInt32Make(cx, cy), low, high) + } MilliSleep(MouseSleep + mouseDelay) return bool(cbool) } +// MoveSmooth move the mouse smooth, +// moves mouse to x, y human like, with the mouse button up. +// +// robotgo.MoveSmooth(x, y int, low, high float64, mouseDelay int) +// +// Examples: +// +// robotgo.MoveSmooth(10, 10) +// robotgo.MoveSmooth(10, 10, 1.0, 2.0) +func MoveSmooth(x, y int, args ...interface{}) bool { + return smoothMove(x, y, false, args...) +} + // MoveArgs get the mouse relative args func MoveArgs(x, y int) (int, int) { mx, my := Location() diff --git a/robotgo_fn_v1.go b/robotgo_fn_v1.go index 4e1de48..037e23f 100644 --- a/robotgo_fn_v1.go +++ b/robotgo_fn_v1.go @@ -25,11 +25,7 @@ func MoveMouse(x, y int) { // DragMouse drag the mouse to (x, y), // It's same with the DragSmooth() now func DragMouse(x, y int, args ...interface{}) { - Toggle("left") - MilliSleep(50) - // Drag(x, y, args...) - MoveSmooth(x, y, args...) - Toggle("left", "up") + DragSmooth(x, y, args...) } // Deprecated: use the MoveSmooth(),