Merge pull request #758 from PekingSpades/pr-macos-desktop-drag

Fix: use drag event for macOS smooth drag
This commit is contained in:
Evans 2026-02-27 08:20:48 -08:00 committed by GitHub
commit a6bd56ea5f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 38 additions and 23 deletions

View file

@ -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);
}

View file

@ -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()

View file

@ -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(),