mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-17 13:33:55 +00:00
Compare commits
7 Commits
b33a84dec2
...
87609e5998
Author | SHA1 | Date | |
---|---|---|---|
![]() |
87609e5998 | ||
![]() |
03432155c1 | ||
![]() |
6a1f060a8c | ||
![]() |
9aa4059a31 | ||
![]() |
31ddf1a959 | ||
![]() |
de95edb1a8 | ||
![]() |
df394a94b8 |
@ -96,25 +96,7 @@ void moveMouse(MMPointInt32 point){
|
|||||||
|
|
||||||
XSync(display, false);
|
XSync(display, false);
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
// Mouse motion is now done using SendInput with MOUSEINPUT.
|
SetCursorPos(point.x, point.y);
|
||||||
// We use Absolute mouse positioning
|
|
||||||
#define MOUSE_COORD_TO_ABS(coord, width_or_height) ( \
|
|
||||||
((65536 * coord) / width_or_height) + (coord < 0 ? -1 : 1))
|
|
||||||
|
|
||||||
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 = 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));
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
window/pub.h
16
window/pub.h
@ -42,7 +42,7 @@ typedef struct _Bounds Bounds;
|
|||||||
static Boolean(*gAXIsProcessTrustedWithOptions) (CFDictionaryRef);
|
static Boolean(*gAXIsProcessTrustedWithOptions) (CFDictionaryRef);
|
||||||
static CFStringRef* gkAXTrustedCheckOptionPrompt;
|
static CFStringRef* gkAXTrustedCheckOptionPrompt;
|
||||||
|
|
||||||
AXError _AXUIElementGetWindow(AXUIElementRef, CGWindowID* out);
|
//AXError _AXUIElementGetWindow(AXUIElementRef, CGWindowID* out);
|
||||||
static AXUIElementRef GetUIElement(CGWindowID win){
|
static AXUIElementRef GetUIElement(CGWindowID win){
|
||||||
intptr pid = 0;
|
intptr pid = 0;
|
||||||
// double_t pid = 0;
|
// double_t pid = 0;
|
||||||
@ -90,13 +90,25 @@ typedef struct _Bounds Bounds;
|
|||||||
AXUIElementRef element = (AXUIElementRef) CFArrayGetValueAtIndex(windows, i);
|
AXUIElementRef element = (AXUIElementRef) CFArrayGetValueAtIndex(windows, i);
|
||||||
CGWindowID temp = 0;
|
CGWindowID temp = 0;
|
||||||
// Use undocumented API to get WindowID
|
// Use undocumented API to get WindowID
|
||||||
_AXUIElementGetWindow(element, &temp);
|
/*_AXUIElementGetWindow(element, &temp);
|
||||||
|
|
||||||
if (temp == win) {
|
if (temp == win) {
|
||||||
// Retain element
|
// Retain element
|
||||||
CFRetain(element);
|
CFRetain(element);
|
||||||
result = element;
|
result = element;
|
||||||
break;
|
break;
|
||||||
|
}*/
|
||||||
|
CFTypeRef cfWindow = NULL;
|
||||||
|
if (AXUIElementCopyAttributeValue(element, kAXWindowAttribute, &cfWindow) == kAXErrorSuccess && cfWindow != NULL) {
|
||||||
|
temp = *(CGWindowID*)CFDataGetBytePtr(cfWindow);
|
||||||
|
CFRelease(cfWindow);
|
||||||
|
|
||||||
|
if (temp == win) {
|
||||||
|
// Retain element
|
||||||
|
CFRetain(element);
|
||||||
|
result = element;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,12 +366,12 @@ MData get_active(void) {
|
|||||||
AXUIElementRef focused = AXUIElementCreateApplication(pid);
|
AXUIElementRef focused = AXUIElementCreateApplication(pid);
|
||||||
if (focused == NULL) { return result; } // Verify
|
if (focused == NULL) { return result; } // Verify
|
||||||
|
|
||||||
AXUIElementRef element;
|
/*AXUIElementRef element;
|
||||||
CGWindowID win = 0;
|
CGWindowID win = 0;
|
||||||
// Retrieve the currently focused window
|
// Retrieve the currently focused window
|
||||||
if (AXUIElementCopyAttributeValue(focused, kAXFocusedWindowAttribute, (CFTypeRef*) &element)
|
if (AXUIElementCopyAttributeValue(focused, kAXFocusedWindowAttribute, (CFTypeRef*) &element)
|
||||||
== kAXErrorSuccess && element) {
|
== kAXErrorSuccess && element) {
|
||||||
|
|
||||||
// Use undocumented API to get WID
|
// Use undocumented API to get WID
|
||||||
if (_AXUIElementGetWindow(element, &win) == kAXErrorSuccess && win) {
|
if (_AXUIElementGetWindow(element, &win) == kAXErrorSuccess && win) {
|
||||||
// Manually set internals
|
// Manually set internals
|
||||||
@ -383,7 +383,31 @@ MData get_active(void) {
|
|||||||
} else {
|
} else {
|
||||||
result.CgID = win;
|
result.CgID = win;
|
||||||
result.AxID = element;
|
result.AxID = element;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
AXUIElementRef windowElement = NULL;
|
||||||
|
CGWindowID win = 0;
|
||||||
|
|
||||||
|
// Retrieve the currently focused window
|
||||||
|
if (AXUIElementCopyAttributeValue(focused, kAXFocusedWindowAttribute, (CFTypeRef*) &windowElement) == kAXErrorSuccess && windowElement) {
|
||||||
|
// Use AXUIElementCopyAttributeValue to get parent window
|
||||||
|
CFTypeRef cfWindow = NULL;
|
||||||
|
if (AXUIElementCopyAttributeValue(windowElement, kAXParentAttribute, &cfWindow) == kAXErrorSuccess && cfWindow != NULL) {
|
||||||
|
AXUIElementRef parentWindow = (AXUIElementRef)cfWindow;
|
||||||
|
if (AXUIElementCopyAttributeValue(parentWindow, kAXWindowAttribute, (CFTypeRef*)&win) == kAXErrorSuccess && win) {
|
||||||
|
// Manually set internals
|
||||||
|
result.CgID = win;
|
||||||
|
result.AxID = windowElement;
|
||||||
|
} else {
|
||||||
|
CFRelease(parentWindow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CFRelease(windowElement);
|
||||||
|
} else {
|
||||||
|
result.CgID = 0;
|
||||||
|
result.AxID = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CFRelease(focused);
|
CFRelease(focused);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user