mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-06 08:43:56 +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
@ -94,8 +94,7 @@ void calculateDeltas(CGEventRef *event, MMPointInt32 point){
|
|||||||
void moveMouse(MMPointInt32 point){
|
void moveMouse(MMPointInt32 point){
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
|
CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
|
||||||
CGPointFromMMPointInt32(point),
|
CGPointFromMMPointInt32(point), kCGMouseButtonLeft);
|
||||||
kCGMouseButtonLeft);
|
|
||||||
|
|
||||||
calculateDeltas(&move, point);
|
calculateDeltas(&move, point);
|
||||||
|
|
||||||
@ -103,8 +102,7 @@ void moveMouse(MMPointInt32 point){
|
|||||||
CFRelease(move);
|
CFRelease(move);
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
Display *display = XGetMainDisplay();
|
Display *display = XGetMainDisplay();
|
||||||
XWarpPointer(display, None, DefaultRootWindow(display),
|
XWarpPointer(display, None, DefaultRootWindow(display), 0, 0, 0, 0, point.x, point.y);
|
||||||
0, 0, 0, 0, point.x, point.y);
|
|
||||||
|
|
||||||
XSync(display, false);
|
XSync(display, false);
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
@ -113,15 +111,17 @@ void moveMouse(MMPointInt32 point){
|
|||||||
#define MOUSE_COORD_TO_ABS(coord, width_or_height) ( \
|
#define MOUSE_COORD_TO_ABS(coord, width_or_height) ( \
|
||||||
((65536 * coord) / width_or_height) + (coord < 0 ? -1 : 1))
|
((65536 * coord) / width_or_height) + (coord < 0 ? -1 : 1))
|
||||||
|
|
||||||
point.x = MOUSE_COORD_TO_ABS(point.x, GetSystemMetrics(SM_CXSCREEN));
|
MMRectInt32 rect = getScreenRect(-1);
|
||||||
point.y = MOUSE_COORD_TO_ABS(point.y, GetSystemMetrics(SM_CYSCREEN));
|
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;
|
INPUT mouseInput;
|
||||||
mouseInput.type = INPUT_MOUSE;
|
mouseInput.type = INPUT_MOUSE;
|
||||||
mouseInput.mi.dx = point.x;
|
mouseInput.mi.dx = x;
|
||||||
mouseInput.mi.dy = point.y;
|
mouseInput.mi.dy = y;
|
||||||
mouseInput.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
|
mouseInput.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE | MOUSEEVENTF_VIRTUALDESK;
|
||||||
mouseInput.mi.time = 0; // System will provide the timestamp
|
mouseInput.mi.time = 0; // System will provide the timestamp
|
||||||
|
|
||||||
mouseInput.mi.dwExtraInfo = 0;
|
mouseInput.mi.dwExtraInfo = 0;
|
||||||
mouseInput.mi.mouseData = 0;
|
mouseInput.mi.mouseData = 0;
|
||||||
SendInput(1, &mouseInput, sizeof(mouseInput));
|
SendInput(1, &mouseInput, sizeof(mouseInput));
|
||||||
@ -190,7 +190,6 @@ void toggleMouse(bool down, MMMouseButton button){
|
|||||||
XSync(display, false);
|
XSync(display, false);
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
// mouse_event(MMMouseToMEventF(down, button), 0, 0, 0, 0);
|
// mouse_event(MMMouseToMEventF(down, button), 0, 0, 0, 0);
|
||||||
|
|
||||||
INPUT mouseInput;
|
INPUT mouseInput;
|
||||||
|
|
||||||
mouseInput.type = INPUT_MOUSE;
|
mouseInput.type = INPUT_MOUSE;
|
||||||
|
10
robotgo.go
10
robotgo.go
@ -192,6 +192,11 @@ func PadHex(hex C.MMRGBHex) string {
|
|||||||
return gcolor
|
return gcolor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PadHexs trans CHex to string
|
||||||
|
func PadHexs(hex CHex) string {
|
||||||
|
return PadHex(C.MMRGBHex(hex))
|
||||||
|
}
|
||||||
|
|
||||||
// HexToRgb trans hex to rgb
|
// HexToRgb trans hex to rgb
|
||||||
func HexToRgb(hex uint32) *C.uint8_t {
|
func HexToRgb(hex uint32) *C.uint8_t {
|
||||||
return C.color_hex_to_rgb(C.uint32_t(hex))
|
return C.color_hex_to_rgb(C.uint32_t(hex))
|
||||||
@ -343,6 +348,11 @@ func FreeBitmap(bitmap CBitmap) {
|
|||||||
C.bitmap_dealloc(C.MMBitmapRef(bitmap))
|
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
|
// ToBitmap trans C.MMBitmapRef to Bitmap
|
||||||
func ToBitmap(bit CBitmap) Bitmap {
|
func ToBitmap(bit CBitmap) Bitmap {
|
||||||
bitmap := Bitmap{
|
bitmap := Bitmap{
|
||||||
|
Loading…
Reference in New Issue
Block a user