From d2f905e308b9153d17b605d1b7d6a967a1475204 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Mon, 3 Jan 2022 21:51:52 -0400 Subject: [PATCH 1/4] add PadHexs and ToMMBitmap support --- robotgo.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/robotgo.go b/robotgo.go index da6a6d9e..5a9cd80d 100644 --- a/robotgo.go +++ b/robotgo.go @@ -192,6 +192,11 @@ func PadHex(hex C.MMRGBHex) string { return gcolor } +// PadHexs trans CHex to string +func PadHexs(hex CHex) string { + return PadHex(C.MMRGBHex(hex)) +} + // HexToRgb trans hex to rgb func HexToRgb(hex uint32) *C.uint8_t { return C.color_hex_to_rgb(C.uint32_t(hex)) @@ -343,6 +348,11 @@ func FreeBitmap(bitmap CBitmap) { C.bitmap_dealloc(C.MMBitmapRef(bitmap)) } +// ToMMBitmapRef trans CBitmap to C.MMBitmapRef +func ToMMBitmapRef(bit CBitmap) C.MMBitmapRef { + return C.MMBitmapRef(bit) +} + // ToBitmap trans C.MMBitmapRef to Bitmap func ToBitmap(bit CBitmap) Bitmap { bitmap := Bitmap{ From a93a984215e121e33c3dfa6946865d7c72993398 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Mon, 3 Jan 2022 21:56:14 -0400 Subject: [PATCH 2/4] add move mouse windows multi screen support --- mouse/mouse_c.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mouse/mouse_c.h b/mouse/mouse_c.h index 1b72e747..ce4595e5 100644 --- a/mouse/mouse_c.h +++ b/mouse/mouse_c.h @@ -113,14 +113,15 @@ void moveMouse(MMPointInt32 point){ #define MOUSE_COORD_TO_ABS(coord, width_or_height) ( \ ((65536 * coord) / width_or_height) + (coord < 0 ? -1 : 1)) - point.x = MOUSE_COORD_TO_ABS(point.x, GetSystemMetrics(SM_CXSCREEN)); - point.y = MOUSE_COORD_TO_ABS(point.y, GetSystemMetrics(SM_CYSCREEN)); + MMRectInt32 rect = getScreenRect(); + size_t x = MOUSE_COORD_TO_ABS(point.x - rect.origin.x, rect.size.w); + size_t y = MOUSE_COORD_TO_ABS(point.y - rect.origin.y, rect.size.h); INPUT mouseInput; mouseInput.type = INPUT_MOUSE; - mouseInput.mi.dx = point.x; - mouseInput.mi.dy = point.y; - mouseInput.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE; + mouseInput.mi.dx = x; + mouseInput.mi.dy = y; + mouseInput.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE | MOUSEEVENTF_VIRTUALDESK; mouseInput.mi.time = 0; // System will provide the timestamp mouseInput.mi.dwExtraInfo = 0; mouseInput.mi.mouseData = 0; From cf237175a75c4fe3cd283b9deb5d127d28d27740 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Mon, 3 Jan 2022 21:59:37 -0400 Subject: [PATCH 3/4] Fixed windows CI --- mouse/mouse_c.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mouse/mouse_c.h b/mouse/mouse_c.h index ce4595e5..b9c4c45e 100644 --- a/mouse/mouse_c.h +++ b/mouse/mouse_c.h @@ -113,7 +113,7 @@ void moveMouse(MMPointInt32 point){ #define MOUSE_COORD_TO_ABS(coord, width_or_height) ( \ ((65536 * coord) / width_or_height) + (coord < 0 ? -1 : 1)) - MMRectInt32 rect = getScreenRect(); + MMRectInt32 rect = getScreenRect(-1); size_t x = MOUSE_COORD_TO_ABS(point.x - rect.origin.x, rect.size.w); size_t y = MOUSE_COORD_TO_ABS(point.y - rect.origin.y, rect.size.h); From 7685ce8a3b309a0eb249b9de55fd2de5976882c0 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Mon, 3 Jan 2022 22:05:39 -0400 Subject: [PATCH 4/4] Update windows int type --- mouse/mouse_c.h | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/mouse/mouse_c.h b/mouse/mouse_c.h index b9c4c45e..d6da85d9 100644 --- a/mouse/mouse_c.h +++ b/mouse/mouse_c.h @@ -93,9 +93,8 @@ void calculateDeltas(CGEventRef *event, MMPointInt32 point){ */ void moveMouse(MMPointInt32 point){ #if defined(IS_MACOSX) - CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, - CGPointFromMMPointInt32(point), - kCGMouseButtonLeft); + CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, + CGPointFromMMPointInt32(point), kCGMouseButtonLeft); calculateDeltas(&move, point); @@ -103,8 +102,7 @@ void moveMouse(MMPointInt32 point){ CFRelease(move); #elif defined(USE_X11) Display *display = XGetMainDisplay(); - XWarpPointer(display, None, DefaultRootWindow(display), - 0, 0, 0, 0, point.x, point.y); + XWarpPointer(display, None, DefaultRootWindow(display), 0, 0, 0, 0, point.x, point.y); XSync(display, false); #elif defined(IS_WINDOWS) @@ -114,8 +112,8 @@ void moveMouse(MMPointInt32 point){ ((65536 * coord) / width_or_height) + (coord < 0 ? -1 : 1)) MMRectInt32 rect = getScreenRect(-1); - size_t x = MOUSE_COORD_TO_ABS(point.x - rect.origin.x, rect.size.w); - size_t y = MOUSE_COORD_TO_ABS(point.y - rect.origin.y, rect.size.h); + int32_t x = MOUSE_COORD_TO_ABS(point.x - rect.origin.x, rect.size.w); + int32_t y = MOUSE_COORD_TO_ABS(point.y - rect.origin.y, rect.size.h); INPUT mouseInput; mouseInput.type = INPUT_MOUSE; @@ -123,6 +121,7 @@ void moveMouse(MMPointInt32 point){ mouseInput.mi.dy = y; mouseInput.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE | MOUSEEVENTF_VIRTUALDESK; mouseInput.mi.time = 0; // System will provide the timestamp + mouseInput.mi.dwExtraInfo = 0; mouseInput.mi.mouseData = 0; SendInput(1, &mouseInput, sizeof(mouseInput)); @@ -133,8 +132,8 @@ void moveMouse(MMPointInt32 point){ void dragMouse(MMPointInt32 point, const MMMouseButton button){ #if defined(IS_MACOSX) const CGEventType dragType = MMMouseDragToCGEventType(button); - CGEventRef drag = CGEventCreateMouseEvent(NULL, dragType, - CGPointFromMMPoint(point), (CGMouseButton)button); + CGEventRef drag = CGEventCreateMouseEvent(NULL, dragType, + CGPointFromMMPoint(point), (CGMouseButton)button); calculateDeltas(&drag, point); @@ -181,7 +180,7 @@ void toggleMouse(bool down, MMMouseButton button){ const CGPoint currentPos = CGPointFromMMPoint(getMousePos()); const CGEventType mouseType = MMMouseToCGEventType(down, button); CGEventRef event = CGEventCreateMouseEvent(NULL, - mouseType, currentPos, (CGMouseButton)button); + mouseType, currentPos, (CGMouseButton)button); CGEventPost(kCGSessionEventTap, event); CFRelease(event); @@ -191,7 +190,6 @@ void toggleMouse(bool down, MMMouseButton button){ XSync(display, false); #elif defined(IS_WINDOWS) // mouse_event(MMMouseToMEventF(down, button), 0, 0, 0, 0); - INPUT mouseInput; mouseInput.type = INPUT_MOUSE; @@ -224,7 +222,7 @@ void doubleClick(MMMouseButton button){ const CGEventType mouseTypeUP = MMMouseToCGEventType(false, button); CGEventRef event = CGEventCreateMouseEvent( - NULL, mouseTypeDown, currentPos, kCGMouseButtonLeft); + NULL, mouseTypeDown, currentPos, kCGMouseButtonLeft); /* Set event to double click. */ CGEventSetIntegerValueField(event, kCGMouseEventClickState, 2); @@ -275,7 +273,7 @@ void scrollMouse(int scrollMagnitude, MMMouseWheelDirection scrollDirection){ cleanScrollMagnitude = cleanScrollMagnitude * scrollDirection; event = CGEventCreateScrollWheelEvent(NULL, - kCGScrollEventUnitLine, wheel, cleanScrollMagnitude, 0); + kCGScrollEventUnitLine, wheel, cleanScrollMagnitude, 0); CGEventPost(kCGHIDEventTap, event);