mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-01 14:43:55 +00:00
Merge pull request #431 from go-vgo/bitmap-pr
add PadHexs and ToMMBitmap support, add move mouse windows multi screen support
This commit is contained in:
commit
adc7bd42d1
@ -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)
|
||||
@ -113,15 +111,17 @@ 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(-1);
|
||||
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;
|
||||
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;
|
||||
SendInput(1, &mouseInput, sizeof(mouseInput));
|
||||
@ -132,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);
|
||||
|
||||
@ -180,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);
|
||||
@ -190,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;
|
||||
@ -223,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);
|
||||
@ -274,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);
|
||||
|
||||
|
10
robotgo.go
10
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{
|
||||
|
Loading…
Reference in New Issue
Block a user