mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-01 14:43:55 +00:00
Merge pull request #457 from go-vgo/bitmap-pr
Refactor some mouse and window C code to Go
This commit is contained in:
commit
fafd2bfcd4
@ -2,7 +2,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
MMBitmapRef createMMBitmap_c(uint8_t *buffer, size_t width, size_t height,
|
MMBitmapRef createMMBitmap_c(uint8_t *buffer, int32_t width, int32_t height,
|
||||||
size_t bytewidth, uint8_t bitsPerPixel, uint8_t bytesPerPixel
|
size_t bytewidth, uint8_t bitsPerPixel, uint8_t bytesPerPixel
|
||||||
) {
|
) {
|
||||||
MMBitmapRef bitmap = malloc(sizeof(MMBitmap));
|
MMBitmapRef bitmap = malloc(sizeof(MMBitmap));
|
||||||
|
@ -5,8 +5,7 @@
|
|||||||
/* Python versions under 2.5 don't support this macro, but it's not
|
/* Python versions under 2.5 don't support this macro, but it's not
|
||||||
* terribly difficult to replicate: */
|
* terribly difficult to replicate: */
|
||||||
#ifndef PyModule_AddIntMacro
|
#ifndef PyModule_AddIntMacro
|
||||||
#define PyModule_AddIntMacro(module, macro) \
|
#define PyModule_AddIntMacro(module, macro) PyModule_AddIntConstant(module, #macro, macro)
|
||||||
PyModule_AddIntConstant(module, #macro, macro)
|
|
||||||
#endif /* PyModule_AddIntMacro */
|
#endif /* PyModule_AddIntMacro */
|
||||||
|
|
||||||
#if !defined(IS_MACOSX) && defined(__APPLE__) && defined(__MACH__)
|
#if !defined(IS_MACOSX) && defined(__APPLE__) && defined(__MACH__)
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "inline_keywords.h" /* For H_INLINE */
|
#include "inline_keywords.h" /* For H_INLINE */
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
/* Some generic, cross-platform types. */
|
/* Some generic, cross-platform types. */
|
||||||
#ifdef RobotGo_64
|
#ifdef RobotGo_64
|
||||||
|
@ -8,6 +8,13 @@ static int registered = 0;
|
|||||||
static char *displayName = NULL;
|
static char *displayName = NULL;
|
||||||
static int hasDisplayNameChanged = 0;
|
static int hasDisplayNameChanged = 0;
|
||||||
|
|
||||||
|
void XCloseMainDisplay(void) {
|
||||||
|
if (mainDisplay != NULL) {
|
||||||
|
XCloseDisplay(mainDisplay);
|
||||||
|
mainDisplay = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Display *XGetMainDisplay(void) {
|
Display *XGetMainDisplay(void) {
|
||||||
/* Close the display if displayName has changed */
|
/* Close the display if displayName has changed */
|
||||||
if (hasDisplayNameChanged) {
|
if (hasDisplayNameChanged) {
|
||||||
@ -40,13 +47,6 @@ Display *XGetMainDisplay(void) {
|
|||||||
return mainDisplay;
|
return mainDisplay;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XCloseMainDisplay(void) {
|
|
||||||
if (mainDisplay != NULL) {
|
|
||||||
XCloseDisplay(mainDisplay);
|
|
||||||
mainDisplay = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setXDisplay(char *name) {
|
void setXDisplay(char *name) {
|
||||||
displayName = strdup(name);
|
displayName = strdup(name);
|
||||||
hasDisplayNameChanged = 1;
|
hasDisplayNameChanged = 1;
|
||||||
|
@ -81,23 +81,23 @@ MMKeyCode keyCodeForChar(const char c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
CFStringRef createStringForKey(CGKeyCode keyCode){
|
CFStringRef createStringForKey(CGKeyCode keyCode){
|
||||||
TISInputSourceRef currentKeyboard = TISCopyCurrentASCIICapableKeyboardInputSource();
|
TISInputSourceRef currentKeyboard = TISCopyCurrentASCIICapableKeyboardInputSource();
|
||||||
CFDataRef layoutData = (CFDataRef) TISGetInputSourceProperty(
|
CFDataRef layoutData = (CFDataRef) TISGetInputSourceProperty(
|
||||||
currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
|
currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
|
||||||
|
|
||||||
if (layoutData == nil) { return 0; }
|
if (layoutData == nil) { return 0; }
|
||||||
|
|
||||||
const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout *) CFDataGetBytePtr(layoutData);
|
const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout *) CFDataGetBytePtr(layoutData);
|
||||||
UInt32 keysDown = 0;
|
UInt32 keysDown = 0;
|
||||||
UniChar chars[4];
|
UniChar chars[4];
|
||||||
UniCharCount realLength;
|
UniCharCount realLength;
|
||||||
|
|
||||||
UCKeyTranslate(keyboardLayout, keyCode, kUCKeyActionDisplay, 0, LMGetKbdType(),
|
UCKeyTranslate(keyboardLayout, keyCode, kUCKeyActionDisplay, 0, LMGetKbdType(),
|
||||||
kUCKeyTranslateNoDeadKeysBit, &keysDown,
|
kUCKeyTranslateNoDeadKeysBit, &keysDown,
|
||||||
sizeof(chars) / sizeof(chars[0]), &realLength, chars);
|
sizeof(chars) / sizeof(chars[0]), &realLength, chars);
|
||||||
CFRelease(currentKeyboard);
|
CFRelease(currentKeyboard);
|
||||||
|
|
||||||
return CFStringCreateWithCharacters(kCFAllocatorDefault, chars, 1);
|
return CFStringCreateWithCharacters(kCFAllocatorDefault, chars, 1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -19,14 +19,14 @@
|
|||||||
Sleep(DEADBEEF_RANDRANGE(0, 1));
|
Sleep(DEADBEEF_RANDRANGE(0, 1));
|
||||||
}
|
}
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
void X_KEY_EVENT(Display *display, MMKeyCode key, bool is_press) (
|
void X_KEY_EVENT(Display *display, MMKeyCode key, bool is_press) {
|
||||||
XTestFakeKeyEvent(display, XKeysymToKeycode(display, key), is_press, CurrentTime);
|
XTestFakeKeyEvent(display, XKeysymToKeycode(display, key), is_press, CurrentTime);
|
||||||
XSync(display, false);
|
XSync(display, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void X_KEY_EVENT_WAIT(Display *display, MMKeyCode key, bool is_press) {
|
void X_KEY_EVENT_WAIT(Display *display, MMKeyCode key, bool is_press) {
|
||||||
X_KEY_EVENT(display, key, is_press);
|
X_KEY_EVENT(display, key, is_press);
|
||||||
microsleep(DEADBEEF_UNIFORM(0.0, 0.5);
|
microsleep(DEADBEEF_UNIFORM(0.0, 0.5));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
106
mouse/goMouse.h
106
mouse/goMouse.h
@ -1,106 +0,0 @@
|
|||||||
// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// https://github.com/go-vgo/robotgo/blob/master/LICENSE
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
#include "../base/types.h"
|
|
||||||
#include "mouse_c.h"
|
|
||||||
|
|
||||||
// Global delays.
|
|
||||||
int mouseDelay = 0;
|
|
||||||
|
|
||||||
int move_mouse(int32_t x, int32_t y){
|
|
||||||
MMPointInt32 point;
|
|
||||||
point = MMPointInt32Make(x, y);
|
|
||||||
moveMouse(point);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int drag_mouse(int32_t x, int32_t y, MMMouseButton button){
|
|
||||||
MMPointInt32 point;
|
|
||||||
point = MMPointInt32Make(x, y);
|
|
||||||
dragMouse(point, button);
|
|
||||||
microsleep(mouseDelay);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool move_mouse_smooth(int32_t x, int32_t y, double lowSpeed,
|
|
||||||
double highSpeed, int msDelay){
|
|
||||||
MMPointInt32 point;
|
|
||||||
point = MMPointInt32Make(x, y);
|
|
||||||
|
|
||||||
bool cbool = smoothlyMoveMouse(point, lowSpeed, highSpeed);
|
|
||||||
microsleep(msDelay);
|
|
||||||
|
|
||||||
return cbool;
|
|
||||||
}
|
|
||||||
|
|
||||||
MMPointInt32 get_mouse_pos(){
|
|
||||||
MMPointInt32 pos = getMousePos();
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
int mouse_click(MMMouseButton button, bool doubleC){
|
|
||||||
if (!doubleC) {
|
|
||||||
clickMouse(button);
|
|
||||||
} else {
|
|
||||||
doubleClick(button);
|
|
||||||
}
|
|
||||||
|
|
||||||
microsleep(mouseDelay);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int mouse_toggle(char* d, MMMouseButton button){
|
|
||||||
bool down = false;
|
|
||||||
if (strcmp(d, "down") == 0) {
|
|
||||||
down = true;
|
|
||||||
} else if (strcmp(d, "up") == 0) {
|
|
||||||
down = false;
|
|
||||||
} else {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
toggleMouse(down, button);
|
|
||||||
microsleep(mouseDelay);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int set_mouse_delay(size_t val){
|
|
||||||
mouseDelay = val;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int scroll(int x, int y, int msDelay){
|
|
||||||
scrollMouseXY(x, y);
|
|
||||||
microsleep(msDelay);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int scroll_mouse(size_t scrollMagnitude, char *s){
|
|
||||||
MMMouseWheelDirection scrollDirection;
|
|
||||||
|
|
||||||
if (strcmp(s, "up") == 0) {
|
|
||||||
scrollDirection = DIRECTION_UP;
|
|
||||||
} else if (strcmp(s, "down") == 0) {
|
|
||||||
scrollDirection = DIRECTION_DOWN;
|
|
||||||
} else {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
scrollMouse(scrollMagnitude, scrollDirection);
|
|
||||||
microsleep(mouseDelay);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -44,10 +44,4 @@
|
|||||||
#error "No mouse button constants set for platform"
|
#error "No mouse button constants set for platform"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum __MMMouseWheelDirection {
|
|
||||||
DIRECTION_DOWN = -1,
|
|
||||||
DIRECTION_UP = 1
|
|
||||||
};
|
|
||||||
typedef int MMMouseWheelDirection;
|
|
||||||
|
|
||||||
#endif /* MOUSE_H */
|
#endif /* MOUSE_H */
|
@ -122,7 +122,7 @@ void dragMouse(MMPointInt32 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,
|
||||||
CGPointFromMMPoint(point), (CGMouseButton)button);
|
CGPointFromMMPointInt32(point), (CGMouseButton)button);
|
||||||
|
|
||||||
calculateDeltas(&drag, point);
|
calculateDeltas(&drag, point);
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ MMPointInt32 getMousePos() {
|
|||||||
/* Press down a button, or release it. */
|
/* Press down a button, or release it. */
|
||||||
void toggleMouse(bool down, MMMouseButton button) {
|
void toggleMouse(bool down, MMMouseButton button) {
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
const CGPoint currentPos = CGPointFromMMPoint(getMousePos());
|
const CGPoint currentPos = CGPointFromMMPointInt32(getMousePos());
|
||||||
const CGEventType mouseType = MMMouseToCGEventType(down, button);
|
const CGEventType mouseType = MMMouseToCGEventType(down, button);
|
||||||
CGEventRef event = CGEventCreateMouseEvent(NULL, mouseType, currentPos, (CGMouseButton)button);
|
CGEventRef event = CGEventCreateMouseEvent(NULL, mouseType, currentPos, (CGMouseButton)button);
|
||||||
|
|
||||||
@ -196,7 +196,7 @@ void clickMouse(MMMouseButton button){
|
|||||||
void doubleClick(MMMouseButton button){
|
void doubleClick(MMMouseButton button){
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
/* Double click for Mac. */
|
/* Double click for Mac. */
|
||||||
const CGPoint currentPos = CGPointFromMMPoint(getMousePos());
|
const CGPoint currentPos = CGPointFromMMPointInt32(getMousePos());
|
||||||
const CGEventType mouseTypeDown = MMMouseToCGEventType(true, button);
|
const CGEventType mouseTypeDown = MMMouseToCGEventType(true, button);
|
||||||
const CGEventType mouseTypeUP = MMMouseToCGEventType(false, button);
|
const CGEventType mouseTypeUP = MMMouseToCGEventType(false, button);
|
||||||
|
|
||||||
@ -219,56 +219,6 @@ void doubleClick(MMMouseButton button){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Function used to scroll the screen in the required direction. */
|
/* Function used to scroll the screen in the required direction. */
|
||||||
void scrollMouse(int scrollMagnitude, MMMouseWheelDirection scrollDirection){
|
|
||||||
#if defined(IS_WINDOWS)
|
|
||||||
// C89 needs variables declared on top of functions (mouseScrollInput)
|
|
||||||
INPUT mouseScrollInput;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Direction should only be considered based on the scrollDirection. This Should not interfere. */
|
|
||||||
int cleanScrollMagnitude = abs(scrollMagnitude);
|
|
||||||
if (!(scrollDirection == DIRECTION_UP || scrollDirection == DIRECTION_DOWN)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set up the OS specific solution */
|
|
||||||
#if defined(__APPLE__)
|
|
||||||
CGWheelCount wheel = 1;
|
|
||||||
CGEventRef event;
|
|
||||||
|
|
||||||
/* Make scroll magnitude negative if we're scrolling down. */
|
|
||||||
cleanScrollMagnitude = cleanScrollMagnitude * scrollDirection;
|
|
||||||
|
|
||||||
event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitLine, wheel, cleanScrollMagnitude, 0);
|
|
||||||
CGEventPost(kCGHIDEventTap, event);
|
|
||||||
#elif defined(USE_X11)
|
|
||||||
int x;
|
|
||||||
int dir = 4; /* Button 4 is up, 5 is down. */
|
|
||||||
Display *display = XGetMainDisplay();
|
|
||||||
|
|
||||||
if (scrollDirection == DIRECTION_DOWN) {
|
|
||||||
dir = 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (x = 0; x < cleanScrollMagnitude; x++) {
|
|
||||||
XTestFakeButtonEvent(display, dir, 1, CurrentTime);
|
|
||||||
XTestFakeButtonEvent(display, dir, 0, CurrentTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
XSync(display, false);
|
|
||||||
#elif defined(IS_WINDOWS)
|
|
||||||
mouseScrollInput.type = INPUT_MOUSE;
|
|
||||||
mouseScrollInput.mi.dx = 0;
|
|
||||||
mouseScrollInput.mi.dy = 0;
|
|
||||||
mouseScrollInput.mi.dwFlags = MOUSEEVENTF_WHEEL;
|
|
||||||
mouseScrollInput.mi.time = 0;
|
|
||||||
mouseScrollInput.mi.dwExtraInfo = 0;
|
|
||||||
mouseScrollInput.mi.mouseData = WHEEL_DELTA * scrollDirection * cleanScrollMagnitude;
|
|
||||||
|
|
||||||
SendInput(1, &mouseScrollInput, sizeof(mouseScrollInput));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void scrollMouseXY(int x, int y) {
|
void scrollMouseXY(int x, int y) {
|
||||||
#if defined(IS_WINDOWS)
|
#if defined(IS_WINDOWS)
|
||||||
// Fix for #97, C89 needs variables declared on top of functions (mouseScrollInput)
|
// Fix for #97, C89 needs variables declared on top of functions (mouseScrollInput)
|
||||||
|
116
robotgo.go
116
robotgo.go
@ -38,13 +38,12 @@ package robotgo
|
|||||||
#cgo windows LDFLAGS: -lgdi32 -luser32
|
#cgo windows LDFLAGS: -lgdi32 -luser32
|
||||||
//
|
//
|
||||||
#include "screen/goScreen.h"
|
#include "screen/goScreen.h"
|
||||||
#include "mouse/goMouse.h"
|
#include "mouse/mouse_c.h"
|
||||||
#include "window/goWindow.h"
|
#include "window/goWindow.h"
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"image"
|
"image"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
@ -129,7 +128,7 @@ func Sleep(tm int) {
|
|||||||
time.Sleep(time.Duration(tm) * time.Second)
|
time.Sleep(time.Duration(tm) * time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MicroSleep time C.microsleep(tm), use the MilliSleep
|
// MicroSleep time C.microsleep(tm), use the MilliSleep()
|
||||||
func MicroSleep(tm float64) {
|
func MicroSleep(tm float64) {
|
||||||
C.microsleep(C.double(tm))
|
C.microsleep(C.double(tm))
|
||||||
}
|
}
|
||||||
@ -250,8 +249,7 @@ func Scaled0(x int, f float64) int {
|
|||||||
|
|
||||||
// GetScreenSize get the screen size
|
// GetScreenSize get the screen size
|
||||||
func GetScreenSize() (int, int) {
|
func GetScreenSize() (int, int) {
|
||||||
size := C.get_screen_size()
|
size := C.getMainDisplaySize()
|
||||||
// fmt.Println("...", size, size.width)
|
|
||||||
return int(size.w), int(size.h)
|
return int(size.w), int(size.h)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,8 +366,8 @@ func ToBitmap(bit CBitmap) Bitmap {
|
|||||||
func ToCBitmap(bit Bitmap) CBitmap {
|
func ToCBitmap(bit Bitmap) CBitmap {
|
||||||
cbitmap := C.createMMBitmap_c(
|
cbitmap := C.createMMBitmap_c(
|
||||||
(*C.uint8_t)(bit.ImgBuf),
|
(*C.uint8_t)(bit.ImgBuf),
|
||||||
C.size_t(bit.Width),
|
C.int32_t(bit.Width),
|
||||||
C.size_t(bit.Height),
|
C.int32_t(bit.Height),
|
||||||
C.size_t(bit.Bytewidth),
|
C.size_t(bit.Bytewidth),
|
||||||
C.uint8_t(bit.BitsPixel),
|
C.uint8_t(bit.BitsPixel),
|
||||||
C.uint8_t(bit.BytesPerPixel),
|
C.uint8_t(bit.BytesPerPixel),
|
||||||
@ -411,7 +409,7 @@ func GetXDisplayName() string {
|
|||||||
//
|
//
|
||||||
// ScaleX get the primary display horizontal DPI scale factor, drop
|
// ScaleX get the primary display horizontal DPI scale factor, drop
|
||||||
func ScaleX() int {
|
func ScaleX() int {
|
||||||
return int(C.scale_x())
|
return int(C.scaleX())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the ScaledF(),
|
// Deprecated: use the ScaledF(),
|
||||||
@ -502,7 +500,7 @@ func Move(x, y int) {
|
|||||||
|
|
||||||
cx := C.int32_t(x)
|
cx := C.int32_t(x)
|
||||||
cy := C.int32_t(y)
|
cy := C.int32_t(y)
|
||||||
C.move_mouse(cx, cy)
|
C.moveMouse(C.MMPointInt32Make(cx, cy))
|
||||||
|
|
||||||
MilliSleep(MouseSleep)
|
MilliSleep(MouseSleep)
|
||||||
}
|
}
|
||||||
@ -532,7 +530,7 @@ func Drag(x, y int, args ...string) {
|
|||||||
button = CheckMouse(args[0])
|
button = CheckMouse(args[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
C.drag_mouse(cx, cy, button)
|
C.dragMouse(C.MMPointInt32Make(cx, cy), button)
|
||||||
MilliSleep(MouseSleep)
|
MilliSleep(MouseSleep)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -590,8 +588,8 @@ func MoveSmooth(x, y int, args ...interface{}) bool {
|
|||||||
high = 3.0
|
high = 3.0
|
||||||
}
|
}
|
||||||
|
|
||||||
cbool := C.move_mouse_smooth(cx, cy, low, high, C.int(mouseDelay))
|
cbool := C.smoothlyMoveMouse(C.MMPointInt32Make(cx, cy), low, high)
|
||||||
MilliSleep(MouseSleep)
|
MilliSleep(MouseSleep + mouseDelay)
|
||||||
|
|
||||||
return bool(cbool)
|
return bool(cbool)
|
||||||
}
|
}
|
||||||
@ -618,7 +616,7 @@ func MoveSmoothRelative(x, y int, args ...interface{}) {
|
|||||||
|
|
||||||
// GetMousePos get the mouse's portion return x, y
|
// GetMousePos get the mouse's portion return x, y
|
||||||
func GetMousePos() (int, int) {
|
func GetMousePos() (int, int) {
|
||||||
pos := C.get_mouse_pos()
|
pos := C.getMousePos()
|
||||||
x := int(pos.x)
|
x := int(pos.x)
|
||||||
y := int(pos.y)
|
y := int(pos.y)
|
||||||
|
|
||||||
@ -645,7 +643,7 @@ func MouseClick(args ...interface{}) {
|
|||||||
func Click(args ...interface{}) {
|
func Click(args ...interface{}) {
|
||||||
var (
|
var (
|
||||||
button C.MMMouseButton = C.LEFT_BUTTON
|
button C.MMMouseButton = C.LEFT_BUTTON
|
||||||
double C.bool
|
double bool
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
@ -653,10 +651,15 @@ func Click(args ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
double = C.bool(args[1].(bool))
|
double = args[1].(bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !double {
|
||||||
|
C.clickMouse(button)
|
||||||
|
} else {
|
||||||
|
C.doubleClick(button)
|
||||||
}
|
}
|
||||||
|
|
||||||
C.mouse_click(button, double)
|
|
||||||
MilliSleep(MouseSleep)
|
MilliSleep(MouseSleep)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -694,56 +697,28 @@ func Toggle(key ...string) error {
|
|||||||
if len(key) > 0 {
|
if len(key) > 0 {
|
||||||
button = CheckMouse(key[0])
|
button = CheckMouse(key[0])
|
||||||
}
|
}
|
||||||
down := C.CString("down")
|
|
||||||
if len(key) > 1 {
|
|
||||||
down = C.CString(key[1])
|
|
||||||
}
|
|
||||||
|
|
||||||
i := C.mouse_toggle(down, button)
|
down := true
|
||||||
C.free(unsafe.Pointer(down))
|
if len(key) > 1 && key[1] == "up" {
|
||||||
MilliSleep(MouseSleep)
|
down = false
|
||||||
if int(i) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
return errors.New("Undefined params.")
|
C.toggleMouse(C.bool(down), button)
|
||||||
|
MilliSleep(MouseSleep)
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the Toggle(),
|
// MouseDown send mouse down event
|
||||||
//
|
func MouseDown(key ...string) error {
|
||||||
// MouseToggle toggle the mouse
|
return Toggle(key...)
|
||||||
//
|
|
||||||
// Examples:
|
|
||||||
// robotgo.MouseToggle("down", "right")
|
|
||||||
// robotgo.MouseToggle("up", "right")
|
|
||||||
func MouseToggle(togKey string, args ...interface{}) int {
|
|
||||||
var button C.MMMouseButton = C.LEFT_BUTTON
|
|
||||||
|
|
||||||
if len(args) > 0 {
|
|
||||||
button = CheckMouse(args[0].(string))
|
|
||||||
}
|
|
||||||
|
|
||||||
down := C.CString(togKey)
|
|
||||||
i := C.mouse_toggle(down, button)
|
|
||||||
|
|
||||||
C.free(unsafe.Pointer(down))
|
|
||||||
MilliSleep(MouseSleep)
|
|
||||||
return int(i)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the Scroll(),
|
// MouseUp send mouse up event
|
||||||
//
|
func MouseUp(key ...string) error {
|
||||||
// ScrollMouse scroll the mouse to (x, "up")
|
if len(key) <= 0 {
|
||||||
//
|
key = append(key, "left")
|
||||||
// Examples:
|
}
|
||||||
// robotgo.ScrollMouse(10, "down")
|
return Toggle(append(key, "up")...)
|
||||||
// robotgo.ScrollMouse(10, "up")
|
|
||||||
func ScrollMouse(x int, direction string) {
|
|
||||||
cx := C.size_t(x)
|
|
||||||
cy := C.CString(direction)
|
|
||||||
C.scroll_mouse(cx, cy)
|
|
||||||
|
|
||||||
C.free(unsafe.Pointer(cy))
|
|
||||||
MilliSleep(MouseSleep)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scroll scroll the mouse to (x, y)
|
// Scroll scroll the mouse to (x, y)
|
||||||
@ -760,10 +735,9 @@ func Scroll(x, y int, args ...int) {
|
|||||||
|
|
||||||
cx := C.int(x)
|
cx := C.int(x)
|
||||||
cy := C.int(y)
|
cy := C.int(y)
|
||||||
cz := C.int(msDelay)
|
|
||||||
|
|
||||||
C.scroll(cx, cy, cz)
|
C.scrollMouseXY(cx, cy)
|
||||||
MilliSleep(MouseSleep)
|
MilliSleep(MouseSleep + msDelay)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScrollSmooth scroll the mouse smooth,
|
// ScrollSmooth scroll the mouse smooth,
|
||||||
@ -809,12 +783,6 @@ func ScrollRelative(x, y int, args ...int) {
|
|||||||
Scroll(mx, my, args...)
|
Scroll(mx, my, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetMouseDelay set mouse delay
|
|
||||||
func SetMouseDelay(delay int) {
|
|
||||||
cdelay := C.size_t(delay)
|
|
||||||
C.set_mouse_delay(cdelay)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
____ __ ____ __ .__ __. _______ ______ ____ __ ____
|
____ __ ____ __ .__ __. _______ ______ ____ __ ____
|
||||||
\ \ / \ / / | | | \ | | | \ / __ \ \ \ / \ / /
|
\ \ / \ / / | | | \ | | | \ / __ \ \ \ / \ / /
|
||||||
@ -850,7 +818,7 @@ func showAlert(title, msg string, args ...string) bool {
|
|||||||
defaultButton := C.CString(defaultBtn)
|
defaultButton := C.CString(defaultBtn)
|
||||||
cancelButton := C.CString(cancelBtn)
|
cancelButton := C.CString(cancelBtn)
|
||||||
|
|
||||||
cbool := C.show_alert(cTitle, cMsg, defaultButton, cancelButton)
|
cbool := C.showAlert(cTitle, cMsg, defaultButton, cancelButton)
|
||||||
ibool := int(cbool)
|
ibool := int(cbool)
|
||||||
|
|
||||||
C.free(unsafe.Pointer(cTitle))
|
C.free(unsafe.Pointer(cTitle))
|
||||||
@ -929,13 +897,13 @@ func CloseWindow(args ...int32) {
|
|||||||
isHwnd = args[1]
|
isHwnd = args[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
C.close_window(C.uintptr(hwnd), C.uintptr(isHwnd))
|
C.close_window_by_PId(C.uintptr(hwnd), C.uintptr(isHwnd))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetHandle set the window handle
|
// SetHandle set the window handle
|
||||||
func SetHandle(hwnd int) {
|
func SetHandle(hwnd int) {
|
||||||
chwnd := C.uintptr(hwnd)
|
chwnd := C.uintptr(hwnd)
|
||||||
C.set_handle(chwnd)
|
C.setHandle(chwnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetHandlePid set the window handle by pid
|
// SetHandlePid set the window handle by pid
|
||||||
@ -973,14 +941,14 @@ func GetHandle() int {
|
|||||||
// This function will be removed in version v1.0.0
|
// This function will be removed in version v1.0.0
|
||||||
func GetBHandle() int {
|
func GetBHandle() int {
|
||||||
tt.Drop("GetBHandle", "GetHandle")
|
tt.Drop("GetBHandle", "GetHandle")
|
||||||
hwnd := C.bget_handle()
|
hwnd := C.b_get_handle()
|
||||||
ghwnd := int(hwnd)
|
ghwnd := int(hwnd)
|
||||||
//fmt.Println("gethwnd---", ghwnd)
|
//fmt.Println("gethwnd---", ghwnd)
|
||||||
return ghwnd
|
return ghwnd
|
||||||
}
|
}
|
||||||
|
|
||||||
func cgetTitle(hwnd, isHwnd int32) string {
|
func cgetTitle(hwnd, isHwnd int32) string {
|
||||||
title := C.get_title(C.uintptr(hwnd), C.uintptr(isHwnd))
|
title := C.get_title_by_pid(C.uintptr(hwnd), C.uintptr(isHwnd))
|
||||||
gtitle := C.GoString(title)
|
gtitle := C.GoString(title)
|
||||||
|
|
||||||
return gtitle
|
return gtitle
|
||||||
|
@ -52,7 +52,6 @@ MMRGBHex get_px_color(int32_t x, int32_t y, int32_t display_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bitmap = copyMMBitmapFromDisplayInRect(MMRectInt32Make(x, y, 1, 1), display_id);
|
bitmap = copyMMBitmapFromDisplayInRect(MMRectInt32Make(x, y, 1, 1), display_id);
|
||||||
// bitmap = MMRectMake(x, y, 1, 1);
|
|
||||||
color = MMRGBHexAtPoint(bitmap, 0, 0);
|
color = MMRGBHexAtPoint(bitmap, 0, 0);
|
||||||
destroyMMBitmap(bitmap);
|
destroyMMBitmap(bitmap);
|
||||||
|
|
||||||
@ -66,12 +65,6 @@ char* get_pixel_color(int32_t x, int32_t y, int32_t display_id) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
MMSizeInt32 get_screen_size() {
|
|
||||||
// Get display size.
|
|
||||||
MMSizeInt32 displaySize = getMainDisplaySize();
|
|
||||||
return displaySize;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* set_XDisplay_name(char* name) {
|
char* set_XDisplay_name(char* name) {
|
||||||
#if defined(USE_X11)
|
#if defined(USE_X11)
|
||||||
setXDisplay(name);
|
setXDisplay(name);
|
||||||
@ -111,7 +104,6 @@ uint32_t get_num_displays() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void bitmap_dealloc(MMBitmapRef bitmap) {
|
void bitmap_dealloc(MMBitmapRef bitmap) {
|
||||||
if (bitmap != NULL) {
|
if (bitmap != NULL) {
|
||||||
destroyMMBitmap(bitmap);
|
destroyMMBitmap(bitmap);
|
||||||
|
@ -95,8 +95,8 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRectInt32 rect, int32_t display_id)
|
|||||||
dib = CreateDIBSection(screen, &bi, DIB_RGB_COLORS, &data, NULL, 0);
|
dib = CreateDIBSection(screen, &bi, DIB_RGB_COLORS, &data, NULL, 0);
|
||||||
|
|
||||||
/* Copy the data into a bitmap struct. */
|
/* Copy the data into a bitmap struct. */
|
||||||
bool smem = (screenMem = CreateCompatibleDC(screen)) == NULL;
|
BOOL smem = (screenMem = CreateCompatibleDC(screen)) == NULL;
|
||||||
bool bitb = BitBlt(screenMem, (int)0, (int)0, (int)rect.size.w, (int)rect.size.h,
|
BOOL bitb = BitBlt(screenMem, (int)0, (int)0, (int)rect.size.w, (int)rect.size.h,
|
||||||
screen, rect.origin.x, rect.origin.y, SRCCOPY);
|
screen, rect.origin.x, rect.origin.y, SRCCOPY);
|
||||||
if (smem || SelectObject(screenMem, dib) == NULL || !bitb) {
|
if (smem || SelectObject(screenMem, dib) == NULL || !bitb) {
|
||||||
/* Error copying data. */
|
/* Error copying data. */
|
||||||
|
@ -12,27 +12,12 @@
|
|||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include "win_sys.h"
|
#include "win_sys.h"
|
||||||
|
|
||||||
int show_alert(const char *title, const char *msg,
|
|
||||||
const char *defaultButton, const char *cancelButton){
|
|
||||||
|
|
||||||
return showAlert(title, msg, defaultButton, cancelButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
intptr scale_x(){
|
|
||||||
return scaleX();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_valid(){
|
|
||||||
return IsValid();
|
|
||||||
}
|
|
||||||
|
|
||||||
void min_window(uintptr pid, bool state, uintptr isHwnd){
|
void min_window(uintptr pid, bool state, uintptr isHwnd){
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
// return 0;
|
// return 0;
|
||||||
AXUIElementRef axID = AXUIElementCreateApplication(pid);
|
AXUIElementRef axID = AXUIElementCreateApplication(pid);
|
||||||
|
AXUIElementSetAttributeValue(axID, kAXMinimizedAttribute,
|
||||||
AXUIElementSetAttributeValue(axID, kAXMinimizedAttribute,
|
state ? kCFBooleanTrue : kCFBooleanFalse);
|
||||||
state ? kCFBooleanTrue : kCFBooleanFalse);
|
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
// Ignore X errors
|
// Ignore X errors
|
||||||
XDismissErrors();
|
XDismissErrors();
|
||||||
@ -64,16 +49,8 @@ void max_window(uintptr pid, bool state, uintptr isHwnd){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void close_window(uintptr pid, uintptr isHwnd){
|
|
||||||
close_window_by_PId(pid, isHwnd);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool set_handle(uintptr handle){
|
|
||||||
return setHandle(handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
uintptr get_handle(){
|
uintptr get_handle(){
|
||||||
MData mData = GetActive();
|
MData mData = get_active();
|
||||||
|
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
return (uintptr)mData.CgID;
|
return (uintptr)mData.CgID;
|
||||||
@ -84,8 +61,7 @@ uintptr get_handle(){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// uint32 uintptr
|
uintptr b_get_handle() {
|
||||||
uintptr getHandle() {
|
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
return (uintptr)mData.CgID;
|
return (uintptr)mData.CgID;
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
@ -95,31 +71,7 @@ uintptr getHandle() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
uintptr bget_handle(){
|
|
||||||
return getHandle();
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_active(const MData win){
|
|
||||||
SetActive(win);
|
|
||||||
}
|
|
||||||
|
|
||||||
void active_PID(uintptr pid, uintptr isHwnd){
|
void active_PID(uintptr pid, uintptr isHwnd){
|
||||||
MData win = set_handle_pid(pid, isHwnd);
|
MData win = set_handle_pid(pid, isHwnd);
|
||||||
SetActive(win);
|
set_active(win);
|
||||||
}
|
|
||||||
|
|
||||||
MData get_active(){
|
|
||||||
MData mdata = GetActive();
|
|
||||||
return mdata;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* get_title(uintptr pid, uintptr isHwnd){
|
|
||||||
char* title = get_title_by_pid(pid, isHwnd);
|
|
||||||
// printf("title::::%s\n", title );
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t get_PID(void){
|
|
||||||
int pid = WGetPID();
|
|
||||||
return pid;
|
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,6 @@ typedef struct _Bounds Bounds;
|
|||||||
static AXUIElementRef GetUIElement(CGWindowID win){
|
static AXUIElementRef GetUIElement(CGWindowID win){
|
||||||
intptr pid = 0;
|
intptr pid = 0;
|
||||||
// double_t pid = 0;
|
// double_t pid = 0;
|
||||||
|
|
||||||
// Create array storing window
|
// Create array storing window
|
||||||
CGWindowID window[1] = { win };
|
CGWindowID window[1] = { win };
|
||||||
CFArrayRef wlist = CFArrayCreate(NULL, (const void**)window, 1, NULL);
|
CFArrayRef wlist = CFArrayCreate(NULL, (const void**)window, 1, NULL);
|
||||||
@ -59,7 +58,6 @@ typedef struct _Bounds Bounds;
|
|||||||
if (info != NULL && CFArrayGetCount(info) > 0) {
|
if (info != NULL && CFArrayGetCount(info) > 0) {
|
||||||
// Retrieve description from info array
|
// Retrieve description from info array
|
||||||
CFDictionaryRef desc = (CFDictionaryRef)CFArrayGetValueAtIndex(info, 0);
|
CFDictionaryRef desc = (CFDictionaryRef)CFArrayGetValueAtIndex(info, 0);
|
||||||
|
|
||||||
// Get window PID
|
// Get window PID
|
||||||
CFNumberRef data = (CFNumberRef) CFDictionaryGetValue(desc, kCGWindowOwnerPID);
|
CFNumberRef data = (CFNumberRef) CFDictionaryGetValue(desc, kCGWindowOwnerPID);
|
||||||
if (data != NULL) {
|
if (data != NULL) {
|
||||||
@ -269,7 +267,6 @@ typedef struct _Bounds Bounds;
|
|||||||
|
|
||||||
|
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
//
|
|
||||||
void win_min(HWND hwnd, bool state){
|
void win_min(HWND hwnd, bool state){
|
||||||
if (state) {
|
if (state) {
|
||||||
ShowWindow(hwnd, SW_MINIMIZE);
|
ShowWindow(hwnd, SW_MINIMIZE);
|
||||||
|
@ -8,10 +8,7 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// #include "../base/os.h"
|
|
||||||
#if defined(USE_X11)
|
#if defined(USE_X11)
|
||||||
// #include <X11/Xlib.h>
|
|
||||||
// #include <X11/Xatom.h>
|
|
||||||
#include <X11/Xresource.h>
|
#include <X11/Xresource.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -79,7 +76,7 @@ intptr scaleX(){
|
|||||||
Bounds get_bounds(uintptr pid, uintptr isHwnd){
|
Bounds get_bounds(uintptr pid, uintptr isHwnd){
|
||||||
// Check if the window is valid
|
// Check if the window is valid
|
||||||
Bounds bounds;
|
Bounds bounds;
|
||||||
if (!IsValid()) { return bounds; }
|
if (!is_valid()) { return bounds; }
|
||||||
|
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
// Bounds bounds;
|
// Bounds bounds;
|
||||||
@ -153,7 +150,7 @@ Bounds get_bounds(uintptr pid, uintptr isHwnd){
|
|||||||
Bounds get_client(uintptr pid, uintptr isHwnd) {
|
Bounds get_client(uintptr pid, uintptr isHwnd) {
|
||||||
// Check if the window is valid
|
// Check if the window is valid
|
||||||
Bounds bounds;
|
Bounds bounds;
|
||||||
if (!IsValid()) { return bounds; }
|
if (!is_valid()) { return bounds; }
|
||||||
|
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
return get_bounds(pid, isHwnd);
|
return get_bounds(pid, isHwnd);
|
||||||
@ -182,9 +179,7 @@ Bounds get_client(uintptr pid, uintptr isHwnd) {
|
|||||||
// Coordinates must be translated
|
// Coordinates must be translated
|
||||||
if (parent != attr.root) {
|
if (parent != attr.root) {
|
||||||
XTranslateCoordinates(rDisplay, win.XWin, attr.root, attr.x, attr.y, &x, &y, &parent);
|
XTranslateCoordinates(rDisplay, win.XWin, attr.root, attr.x, attr.y, &x, &y, &parent);
|
||||||
}
|
} else {
|
||||||
// Coordinates can be left alone
|
|
||||||
else {
|
|
||||||
x = attr.x;
|
x = attr.x;
|
||||||
y = attr.y;
|
y = attr.y;
|
||||||
}
|
}
|
||||||
@ -200,7 +195,7 @@ Bounds get_client(uintptr pid, uintptr isHwnd) {
|
|||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
if (isHwnd == 0) {
|
if (isHwnd == 0) {
|
||||||
hwnd= GetHwndByPId(pid);
|
hwnd = GetHwndByPId(pid);
|
||||||
} else {
|
} else {
|
||||||
hwnd = (HWND)pid;
|
hwnd = (HWND)pid;
|
||||||
}
|
}
|
||||||
|
@ -8,13 +8,13 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// #include "../base/os.h"
|
|
||||||
#include "pub.h"
|
#include "pub.h"
|
||||||
|
|
||||||
bool setHandle(uintptr handle);
|
bool setHandle(uintptr handle);
|
||||||
bool IsValid();
|
bool is_valid();
|
||||||
bool IsAxEnabled(bool options);
|
bool IsAxEnabled(bool options);
|
||||||
MData GetActive(void);
|
|
||||||
|
MData get_active(void);
|
||||||
void initWindow();
|
void initWindow();
|
||||||
char* get_title_by_hand(MData m_data);
|
char* get_title_by_hand(MData m_data);
|
||||||
void close_window_by_Id(MData m_data);
|
void close_window_by_Id(MData m_data);
|
||||||
@ -74,13 +74,13 @@ void set_handle_pid_mData(uintptr pid, uintptr isHwnd){
|
|||||||
mData = win;
|
mData = win;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsValid() {
|
bool is_valid() {
|
||||||
initWindow(initHandle);
|
initWindow(initHandle);
|
||||||
if (!IsAxEnabled(true)) {
|
if (!IsAxEnabled(true)) {
|
||||||
printf("%s\n", "Window: Accessibility API is disabled!\n"
|
printf("%s\n", "Window: Accessibility API is disabled!\n"
|
||||||
"Failed to enable access for assistive devices.");
|
"Failed to enable access for assistive devices.");
|
||||||
}
|
}
|
||||||
MData actdata = GetActive();
|
MData actdata = get_active();
|
||||||
|
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
mData.CgID = actdata.CgID;
|
mData.CgID = actdata.CgID;
|
||||||
@ -131,16 +131,13 @@ bool IsAxEnabled(bool options){
|
|||||||
static dispatch_once_t once; dispatch_once (&once,
|
static dispatch_once_t once; dispatch_once (&once,
|
||||||
^{
|
^{
|
||||||
// Open the framework
|
// Open the framework
|
||||||
void* handle = dlopen("/System/Library/Frameworks/Application"
|
void* handle = dlopen("/System/Library/Frameworks/Application"
|
||||||
"Services.framework/ApplicationServices", RTLD_LAZY);
|
"Services.framework/ApplicationServices", RTLD_LAZY);
|
||||||
|
|
||||||
// Validate the handle
|
// Validate the handle
|
||||||
if (handle != NULL) {
|
if (handle != NULL) {
|
||||||
*(void**) (&gAXIsProcessTrustedWithOptions) =
|
*(void**) (&gAXIsProcessTrustedWithOptions) = dlsym (handle, "AXIsProcessTrustedWithOptions");
|
||||||
dlsym (handle, "AXIsProcessTrustedWithOptions");
|
gkAXTrustedCheckOptionPrompt = (CFStringRef*) dlsym (handle, "kAXTrustedCheckOptionPrompt");
|
||||||
|
|
||||||
gkAXTrustedCheckOptionPrompt =
|
|
||||||
(CFStringRef*) dlsym (handle, "kAXTrustedCheckOptionPrompt");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -207,11 +204,11 @@ bool setHandle(uintptr handle){
|
|||||||
return false;
|
return false;
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
mData.XWin = (Window)handle;
|
mData.XWin = (Window)handle;
|
||||||
if (handle == 0){
|
if (handle == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsValid()){
|
if (is_valid()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,7 +220,7 @@ bool setHandle(uintptr handle){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsValid()) {
|
if (is_valid()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +231,7 @@ bool setHandle(uintptr handle){
|
|||||||
|
|
||||||
bool IsTopMost(void){
|
bool IsTopMost(void){
|
||||||
// Check the window validity
|
// Check the window validity
|
||||||
if (!IsValid()) {return false;}
|
if (!is_valid()) { return false; }
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
return false; // WARNING: Unavailable
|
return false; // WARNING: Unavailable
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
@ -248,7 +245,7 @@ bool IsTopMost(void){
|
|||||||
|
|
||||||
bool IsMinimized(void){
|
bool IsMinimized(void){
|
||||||
// Check the window validity
|
// Check the window validity
|
||||||
if (!IsValid()) {return false;}
|
if (!is_valid()) { return false; }
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
CFBooleanRef data = NULL;
|
CFBooleanRef data = NULL;
|
||||||
// Determine whether the window is minimized
|
// Determine whether the window is minimized
|
||||||
@ -273,7 +270,7 @@ bool IsMinimized(void){
|
|||||||
//////
|
//////
|
||||||
bool IsMaximized(void){
|
bool IsMaximized(void){
|
||||||
// Check the window validity
|
// Check the window validity
|
||||||
if (!IsValid()) {return false;}
|
if (!is_valid()) { return false; }
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
return false; // WARNING: Unavailable
|
return false; // WARNING: Unavailable
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
@ -285,16 +282,15 @@ bool IsMaximized(void){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetActive(const MData win) {
|
void set_active(const MData win) {
|
||||||
// Check if the window is valid
|
// Check if the window is valid
|
||||||
if (!IsValid()) { return; }
|
if (!is_valid()) { return; }
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
// Attempt to raise the specified window object
|
// Attempt to raise the specified window object
|
||||||
if (AXUIElementPerformAction(win.AxID, kAXRaiseAction) != kAXErrorSuccess) {
|
if (AXUIElementPerformAction(win.AxID, kAXRaiseAction) != kAXErrorSuccess) {
|
||||||
pid_t pid = 0;
|
pid_t pid = 0;
|
||||||
// Attempt to retrieve the PID of the window
|
// Attempt to retrieve the PID of the window
|
||||||
if (AXUIElementGetPid(win.AxID, &pid)
|
if (AXUIElementGetPid(win.AxID, &pid) != kAXErrorSuccess || !pid) { return; }
|
||||||
!= kAXErrorSuccess || !pid) {return;}
|
|
||||||
|
|
||||||
// Ignore deprecated warnings
|
// Ignore deprecated warnings
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
@ -309,7 +305,6 @@ void SetActive(const MData win) {
|
|||||||
|
|
||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
// Ignore X errors
|
// Ignore X errors
|
||||||
XDismissErrors();
|
XDismissErrors();
|
||||||
@ -355,7 +350,7 @@ void SetActive(const MData win) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
MData GetActive(void) {
|
MData get_active(void) {
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
MData result;
|
MData result;
|
||||||
// Ignore deprecated warnings
|
// Ignore deprecated warnings
|
||||||
@ -372,7 +367,7 @@ MData GetActive(void) {
|
|||||||
|
|
||||||
// Create accessibility object using focused PID
|
// Create accessibility object using focused PID
|
||||||
AXUIElementRef focused = AXUIElementCreateApplication(pid);
|
AXUIElementRef focused = AXUIElementCreateApplication(pid);
|
||||||
if (focused == NULL) {return result; }// Verify
|
if (focused == NULL) { return result; } // Verify
|
||||||
|
|
||||||
AXUIElementRef element;
|
AXUIElementRef element;
|
||||||
// Retrieve the currently focused window
|
// Retrieve the currently focused window
|
||||||
@ -449,10 +444,9 @@ MData GetActive(void) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SetTopMost(bool state){
|
void SetTopMost(bool state){
|
||||||
// Check window validity
|
// Check window validity
|
||||||
if (!IsValid()) {return;}
|
if (!is_valid()) { return; }
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
// WARNING: Unavailable
|
// WARNING: Unavailable
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
@ -465,9 +459,9 @@ void SetTopMost(bool state){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void close_main_window (){
|
void close_main_window () {
|
||||||
// Check if the window is valid
|
// Check if the window is valid
|
||||||
if (!IsValid()) { return; }
|
if (!is_valid()) { return; }
|
||||||
|
|
||||||
close_window_by_Id(mData);
|
close_window_by_Id(mData);
|
||||||
}
|
}
|
||||||
@ -477,11 +471,10 @@ void close_window_by_PId(uintptr pid, uintptr isHwnd){
|
|||||||
close_window_by_Id(win);
|
close_window_by_Id(win);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// CloseWindow
|
// CloseWindow
|
||||||
void close_window_by_Id(MData m_data){
|
void close_window_by_Id(MData m_data){
|
||||||
// Check window validity
|
// Check window validity
|
||||||
if (!IsValid()) { return; }
|
if (!is_valid()) { return; }
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
AXUIElementRef b = NULL;
|
AXUIElementRef b = NULL;
|
||||||
// Retrieve the close button of this window
|
// Retrieve the close button of this window
|
||||||
@ -506,7 +499,7 @@ void close_window_by_Id(MData m_data){
|
|||||||
|
|
||||||
char* get_main_title(){
|
char* get_main_title(){
|
||||||
// Check if the window is valid
|
// Check if the window is valid
|
||||||
if (!IsValid()) { return "IsValid failed."; }
|
if (!is_valid()) { return "is_valid failed."; }
|
||||||
|
|
||||||
return get_title_by_hand(mData);
|
return get_title_by_hand(mData);
|
||||||
}
|
}
|
||||||
@ -532,7 +525,7 @@ char* named(void *result) {
|
|||||||
|
|
||||||
char* get_title_by_hand(MData m_data){
|
char* get_title_by_hand(MData m_data){
|
||||||
// Check if the window is valid
|
// Check if the window is valid
|
||||||
if (!IsValid()) { return "IsValid failed."; }
|
if (!is_valid()) { return "is_valid failed."; }
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
CFStringRef data = NULL;
|
CFStringRef data = NULL;
|
||||||
// Determine the current title of the window
|
// Determine the current title of the window
|
||||||
@ -591,16 +584,15 @@ char* get_title_by_hand(MData m_data){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t WGetPID(void) {
|
int32_t get_PID(void) {
|
||||||
// Check window validity
|
// Check window validity
|
||||||
if (!IsValid()) { return 0; }
|
if (!is_valid()) { return 0; }
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
pid_t pid = 0;
|
pid_t pid = 0;
|
||||||
// Attempt to retrieve the window pid
|
// Attempt to retrieve the window pid
|
||||||
if (AXUIElementGetPid(mData.AxID, &pid)== kAXErrorSuccess) {
|
if (AXUIElementGetPid(mData.AxID, &pid)== kAXErrorSuccess) {
|
||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
// Ignore X errors
|
// Ignore X errors
|
||||||
@ -620,4 +612,3 @@ int32_t WGetPID(void) {
|
|||||||
return id;
|
return id;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user