mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-03 07:33:55 +00:00
add drag and move mouse multiple screens support
This commit is contained in:
parent
a3da8915b9
commit
4df22c5baa
@ -35,24 +35,24 @@ int mouseDelay = 10;
|
|||||||
// return 0;
|
// return 0;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
int move_mouse(size_t x, size_t y){
|
int move_mouse(int32_t x, int32_t y){
|
||||||
MMPoint point;
|
MMSignedPoint point;
|
||||||
// int x = 103;
|
// int x = 103;
|
||||||
// int y = 104;
|
// int y = 104;
|
||||||
point = MMPointMake(x, y);
|
point = MMSignedPointMake(x, y);
|
||||||
moveMouse(point);
|
moveMouse(point);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int drag_mouse(size_t x, size_t y, MMMouseButton button){
|
int drag_mouse(int32_t x, int32_t y, MMMouseButton button){
|
||||||
// const size_t x = 10;
|
// const size_t x = 10;
|
||||||
// const size_t y = 20;
|
// const size_t y = 20;
|
||||||
// MMMouseButton button = LEFT_BUTTON;
|
// MMMouseButton button = LEFT_BUTTON;
|
||||||
|
|
||||||
MMPoint point;
|
MMSignedPoint point;
|
||||||
point = MMPointMake(x, y);
|
point = MMSignedPointMake(x, y);
|
||||||
dragMouse(point, button);
|
dragMouse(point, button);
|
||||||
microsleep(mouseDelay);
|
microsleep(mouseDelay);
|
||||||
|
|
||||||
|
@ -65,13 +65,13 @@ typedef int MMMouseWheelDirection;
|
|||||||
/* Immediately moves the mouse to the given point on-screen.
|
/* Immediately moves the mouse to the given point on-screen.
|
||||||
* It is up to the caller to ensure that this point is within the
|
* It is up to the caller to ensure that this point is within the
|
||||||
* screen boundaries. */
|
* screen boundaries. */
|
||||||
void moveMouse(MMPoint point);
|
void moveMouse(MMSignedPoint point);
|
||||||
|
|
||||||
/* Like moveMouse, moves the mouse to the given point on-screen, but marks
|
/* Like moveMouse, moves the mouse to the given point on-screen, but marks
|
||||||
* the event as the mouse being dragged on platforms where it is supported.
|
* the event as the mouse being dragged on platforms where it is supported.
|
||||||
* It is up to the caller to ensure that this point is within the screen
|
* It is up to the caller to ensure that this point is within the screen
|
||||||
* boundaries. */
|
* boundaries. */
|
||||||
void dragMouse(MMPoint point, const MMMouseButton button);
|
void dragMouse(MMSignedPoint point, const MMMouseButton button);
|
||||||
|
|
||||||
/* Smoothly moves the mouse from the current position to the given point.
|
/* Smoothly moves the mouse from the current position to the given point.
|
||||||
* deadbeef_srand() should be called before using this function.
|
* deadbeef_srand() should be called before using this function.
|
||||||
|
@ -66,7 +66,7 @@
|
|||||||
* @param event The mouse move event (by ref).
|
* @param event The mouse move event (by ref).
|
||||||
* @param point The new mouse x and y.
|
* @param point The new mouse x and y.
|
||||||
*/
|
*/
|
||||||
void calculateDeltas(CGEventRef *event, MMPoint point){
|
void calculateDeltas(CGEventRef *event, MMSignedPoint point){
|
||||||
/**
|
/**
|
||||||
* The next few lines are a workaround for games not detecting mouse moves.
|
* The next few lines are a workaround for games not detecting mouse moves.
|
||||||
* See this issue for more information:
|
* See this issue for more information:
|
||||||
@ -91,10 +91,10 @@ void calculateDeltas(CGEventRef *event, MMPoint point){
|
|||||||
* Move the mouse to a specific point.
|
* Move the mouse to a specific point.
|
||||||
* @param point The coordinates to move the mouse to (x, y).
|
* @param point The coordinates to move the mouse to (x, y).
|
||||||
*/
|
*/
|
||||||
void moveMouse(MMPoint point){
|
void moveMouse(MMSignedPoint point){
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
|
CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
|
||||||
CGPointFromMMPoint(point),
|
CGPointFromMMSignedPoint(point),
|
||||||
kCGMouseButtonLeft);
|
kCGMouseButtonLeft);
|
||||||
|
|
||||||
calculateDeltas(&move, point);
|
calculateDeltas(&move, point);
|
||||||
@ -129,7 +129,7 @@ void moveMouse(MMPoint point){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void dragMouse(MMPoint point, const MMMouseButton button){
|
void dragMouse(MMSignedPoint point, const MMMouseButton button){
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
const CGEventType dragType = MMMouseDragToCGEventType(button);
|
const CGEventType dragType = MMMouseDragToCGEventType(button);
|
||||||
CGEventRef drag = CGEventCreateMouseEvent(NULL, dragType,
|
CGEventRef drag = CGEventCreateMouseEvent(NULL, dragType,
|
||||||
@ -432,7 +432,7 @@ bool smoothlyMoveMouse(MMPoint endPoint, double lowSpeed, double highSpeed){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
moveMouse(pos);
|
moveMouse(MMSignedPointMake((int32_t)pos.x, (int32_t)pos.y));
|
||||||
|
|
||||||
/* Wait 1 - 3 milliseconds. */
|
/* Wait 1 - 3 milliseconds. */
|
||||||
microsleep(DEADBEEF_UNIFORM(lowSpeed, highSpeed));
|
microsleep(DEADBEEF_UNIFORM(lowSpeed, highSpeed));
|
||||||
|
@ -359,8 +359,8 @@ func MoveMouse(x, y int) {
|
|||||||
|
|
||||||
// Move move the mouse
|
// Move move the mouse
|
||||||
func Move(x, y int) {
|
func Move(x, y int) {
|
||||||
cx := C.size_t(x)
|
cx := C.int32_t(x)
|
||||||
cy := C.size_t(y)
|
cy := C.int32_t(y)
|
||||||
C.move_mouse(cx, cy)
|
C.move_mouse(cx, cy)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,8 +373,8 @@ func DragMouse(x, y int, args ...string) {
|
|||||||
func Drag(x, y int, args ...string) {
|
func Drag(x, y int, args ...string) {
|
||||||
var button C.MMMouseButton = C.LEFT_BUTTON
|
var button C.MMMouseButton = C.LEFT_BUTTON
|
||||||
|
|
||||||
cx := C.size_t(x)
|
cx := C.int32_t(x)
|
||||||
cy := C.size_t(y)
|
cy := C.int32_t(y)
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
button = CheckMouse(args[0])
|
button = CheckMouse(args[0])
|
||||||
|
Loading…
Reference in New Issue
Block a user