Update: update and remove some old code

This commit is contained in:
vcaesar 2023-07-06 10:14:42 -07:00
parent 6fa2f418fa
commit 5c3cbd6e17
3 changed files with 180 additions and 181 deletions

View File

@ -65,7 +65,7 @@
return 0; return 0;
} }
static io_connect_t _getAuxiliaryKeyDriver(void) { static io_connect_t _getAuxiliaryKeyDriver(void) {
static mach_port_t sEventDrvrRef = 0; static mach_port_t sEventDrvrRef = 0;
mach_port_t masterPort, service, iter; mach_port_t masterPort, service, iter;
kern_return_t kr; kern_return_t kr;
@ -86,11 +86,10 @@ static io_connect_t _getAuxiliaryKeyDriver(void) {
IOObjectRelease(iter); IOObjectRelease(iter);
} }
return sEventDrvrRef; return sEventDrvrRef;
} }
#endif #elif defined(IS_WINDOWS)
#if defined(IS_WINDOWS) void win32KeyEvent(int key, MMKeyFlags flags, uintptr pid, int8_t isPid) {
void win32KeyEvent(int key, MMKeyFlags flags, uintptr pid, int8_t isPid) {
int scan = MapVirtualKey(key & 0xff, MAPVK_VK_TO_VSC); int scan = MapVirtualKey(key & 0xff, MAPVK_VK_TO_VSC);
/* Set the scan code for extended keys */ /* Set the scan code for extended keys */
@ -158,7 +157,7 @@ void win32KeyEvent(int key, MMKeyFlags flags, uintptr pid, int8_t isPid) {
keyInput.ki.time = 0; keyInput.ki.time = 0;
keyInput.ki.dwExtraInfo = 0; keyInput.ki.dwExtraInfo = 0;
SendInput(1, &keyInput, sizeof(keyInput)); SendInput(1, &keyInput, sizeof(keyInput));
} }
#endif #endif
void toggleKeyCode(MMKeyCode code, const bool down, MMKeyFlags flags, uintptr pid) { void toggleKeyCode(MMKeyCode code, const bool down, MMKeyFlags flags, uintptr pid) {
@ -269,7 +268,7 @@ void toggleKey(char c, const bool down, MMKeyFlags flags, uintptr pid) {
// } // }
#if defined(IS_MACOSX) #if defined(IS_MACOSX)
void toggleUnicode(UniChar ch, const bool down, uintptr pid) { void toggleUnicode(UniChar ch, const bool down, uintptr pid) {
/* This function relies on the convenient CGEventKeyboardSetUnicodeString(), /* This function relies on the convenient CGEventKeyboardSetUnicodeString(),
convert characters to a keycode, but does not support adding modifier flags. convert characters to a keycode, but does not support adding modifier flags.
It is only used in typeString(). It is only used in typeString().
@ -283,43 +282,13 @@ void toggleUnicode(UniChar ch, const bool down, uintptr pid) {
CGEventKeyboardSetUnicodeString(keyEvent, 1, &ch); CGEventKeyboardSetUnicodeString(keyEvent, 1, &ch);
SendTo(pid, keyEvent); SendTo(pid, keyEvent);
} }
#endif #else
#if defined(USE_X11)
#define toggleUniKey(c, down) toggleKey(c, down, MOD_NONE, 0) #define toggleUniKey(c, down) toggleKey(c, down, MOD_NONE, 0)
int input_utf(const char *utf) {
Display *dpy = XOpenDisplay(NULL);
KeySym sym = XStringToKeysym(utf);
// KeySym sym = XKeycodeToKeysym(dpy, utf);
int min, max, numcodes;
XDisplayKeycodes(dpy, &min, &max);
KeySym *keysym;
keysym = XGetKeyboardMapping(dpy, min, max-min+1, &numcodes);
keysym[(max-min-1)*numcodes] = sym;
XChangeKeyboardMapping(dpy, min, numcodes, keysym, (max-min));
XFree(keysym);
XFlush(dpy);
KeyCode code = XKeysymToKeycode(dpy, sym);
XTestFakeKeyEvent(dpy, code, True, 1);
XTestFakeKeyEvent(dpy, code, False, 1);
XFlush(dpy);
XCloseDisplay(dpy);
return 0;
}
#endif
#if !defined(USE_X11)
int input_utf(const char *utf){
return 0;
}
#endif #endif
// unicode type // unicode type
void unicodeType(const unsigned value, uintptr pid, int8_t isPid){ void unicodeType(const unsigned value, uintptr pid, int8_t isPid) {
#if defined(IS_MACOSX) #if defined(IS_MACOSX)
UniChar ch = (UniChar)value; // Convert to unsigned char UniChar ch = (UniChar)value; // Convert to unsigned char
@ -355,3 +324,32 @@ void unicodeType(const unsigned value, uintptr pid, int8_t isPid){
toggleUniKey(value, false); toggleUniKey(value, false);
#endif #endif
} }
#if defined(USE_X11)
int input_utf(const char *utf) {
Display *dpy = XOpenDisplay(NULL);
KeySym sym = XStringToKeysym(utf);
// KeySym sym = XKeycodeToKeysym(dpy, utf);
int min, max, numcodes;
XDisplayKeycodes(dpy, &min, &max);
KeySym *keysym;
keysym = XGetKeyboardMapping(dpy, min, max-min+1, &numcodes);
keysym[(max-min-1)*numcodes] = sym;
XChangeKeyboardMapping(dpy, min, numcodes, keysym, (max-min));
XFree(keysym);
XFlush(dpy);
KeyCode code = XKeysymToKeycode(dpy, sym);
XTestFakeKeyEvent(dpy, code, True, 1);
XTestFakeKeyEvent(dpy, code, False, 1);
XFlush(dpy);
XCloseDisplay(dpy);
return 0;
}
#else
int input_utf(const char *utf){
return 0;
}
#endif

View File

@ -15,7 +15,7 @@
/* Some convenience macros for converting our enums to the system API types. */ /* Some convenience macros for converting our enums to the system API types. */
#if defined(IS_MACOSX) #if defined(IS_MACOSX)
CGEventType MMMouseDownToCGEventType(MMMouseButton button) { CGEventType MMMouseDownToCGEventType(MMMouseButton button) {
if (button == LEFT_BUTTON) { if (button == LEFT_BUTTON) {
return kCGEventLeftMouseDown; return kCGEventLeftMouseDown;
} }
@ -23,48 +23,48 @@ CGEventType MMMouseDownToCGEventType(MMMouseButton button) {
return kCGEventRightMouseDown; return kCGEventRightMouseDown;
} }
return kCGEventOtherMouseDown; return kCGEventOtherMouseDown;
} }
CGEventType MMMouseUpToCGEventType(MMMouseButton button) { CGEventType MMMouseUpToCGEventType(MMMouseButton button) {
if (button == LEFT_BUTTON) { return kCGEventLeftMouseUp; } if (button == LEFT_BUTTON) { return kCGEventLeftMouseUp; }
if (button == RIGHT_BUTTON) { return kCGEventRightMouseUp; } if (button == RIGHT_BUTTON) { return kCGEventRightMouseUp; }
return kCGEventOtherMouseUp; return kCGEventOtherMouseUp;
} }
CGEventType MMMouseDragToCGEventType(MMMouseButton button) { CGEventType MMMouseDragToCGEventType(MMMouseButton button) {
if (button == LEFT_BUTTON) { return kCGEventLeftMouseDragged; } if (button == LEFT_BUTTON) { return kCGEventLeftMouseDragged; }
if (button == RIGHT_BUTTON) { return kCGEventRightMouseDragged; } if (button == RIGHT_BUTTON) { return kCGEventRightMouseDragged; }
return kCGEventOtherMouseDragged; return kCGEventOtherMouseDragged;
} }
CGEventType MMMouseToCGEventType(bool down, MMMouseButton button) { CGEventType MMMouseToCGEventType(bool down, MMMouseButton button) {
if (down) { return MMMouseDownToCGEventType(button); } if (down) { return MMMouseDownToCGEventType(button); }
return MMMouseUpToCGEventType(button); return MMMouseUpToCGEventType(button);
} }
#elif defined(IS_WINDOWS) #elif defined(IS_WINDOWS)
DWORD MMMouseUpToMEventF(MMMouseButton button) { DWORD MMMouseUpToMEventF(MMMouseButton button) {
if (button == LEFT_BUTTON) { return MOUSEEVENTF_LEFTUP; } if (button == LEFT_BUTTON) { return MOUSEEVENTF_LEFTUP; }
if (button == RIGHT_BUTTON) { return MOUSEEVENTF_RIGHTUP; } if (button == RIGHT_BUTTON) { return MOUSEEVENTF_RIGHTUP; }
return MOUSEEVENTF_MIDDLEUP; return MOUSEEVENTF_MIDDLEUP;
} }
DWORD MMMouseDownToMEventF(MMMouseButton button) { DWORD MMMouseDownToMEventF(MMMouseButton button) {
if (button == LEFT_BUTTON) { return MOUSEEVENTF_LEFTDOWN; } if (button == LEFT_BUTTON) { return MOUSEEVENTF_LEFTDOWN; }
if (button == RIGHT_BUTTON) { return MOUSEEVENTF_RIGHTDOWN; } if (button == RIGHT_BUTTON) { return MOUSEEVENTF_RIGHTDOWN; }
return MOUSEEVENTF_MIDDLEDOWN; return MOUSEEVENTF_MIDDLEDOWN;
} }
DWORD MMMouseToMEventF(bool down, MMMouseButton button) { DWORD MMMouseToMEventF(bool down, MMMouseButton button) {
if (down) { return MMMouseDownToMEventF(button); } if (down) { return MMMouseDownToMEventF(button); }
return MMMouseUpToMEventF(button); return MMMouseUpToMEventF(button);
} }
#endif #endif
#if defined(IS_MACOSX) #if defined(IS_MACOSX)
/* Calculate the delta for a mouse move and add them to the event. */ /* Calculate the delta for a mouse move and add them to the event. */
void calculateDeltas(CGEventRef *event, MMPointInt32 point){ void calculateDeltas(CGEventRef *event, MMPointInt32 point) {
/* The next few lines are a workaround for games not detecting mouse moves. */ /* The next few lines are a workaround for games not detecting mouse moves. */
CGEventRef get = CGEventCreate(NULL); CGEventRef get = CGEventCreate(NULL);
CGPoint mouse = CGEventGetLocation(get); CGPoint mouse = CGEventGetLocation(get);
@ -77,7 +77,7 @@ void calculateDeltas(CGEventRef *event, MMPointInt32 point){
CGEventSetIntegerValueField(*event, kCGMouseEventDeltaY, deltaY); CGEventSetIntegerValueField(*event, kCGMouseEventDeltaY, deltaY);
CFRelease(get); CFRelease(get);
} }
#endif #endif
/* Move the mouse to a specific point. */ /* Move the mouse to a specific point. */

View File

@ -54,7 +54,8 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRectInt32 rect, int32_t display_id,
MMPointInt32 o = rect.origin; MMSizeInt32 s = rect.size; MMPointInt32 o = rect.origin; MMSizeInt32 s = rect.size;
XImage *image = XGetImage(display, XDefaultRootWindow(display), XImage *image = XGetImage(display, XDefaultRootWindow(display),
(int)o.x, (int)o.y, (unsigned int)s.w, (unsigned int)s.h, AllPlanes, ZPixmap); (int)o.x, (int)o.y, (unsigned int)s.w, (unsigned int)s.h,
AllPlanes, ZPixmap);
XCloseDisplay(display); XCloseDisplay(display);
if (image == NULL) { return NULL; } if (image == NULL) { return NULL; }