mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-01 14:43:55 +00:00
Merge pull request #449 from go-vgo/bitmap-pr
Update README.md and removed type_string_delayed
This commit is contained in:
commit
72167ef467
16
README.md
16
README.md
@ -251,16 +251,16 @@ func main() {
|
|||||||
imgo.Save("test.png", img)
|
imgo.Save("test.png", img)
|
||||||
|
|
||||||
num := robotgo.DisplaysNum()
|
num := robotgo.DisplaysNum()
|
||||||
for i := 0; i < num; i++ {
|
for i := 0; i < num; i++ {
|
||||||
robotgo.DisplayID = i
|
robotgo.DisplayID = i
|
||||||
img1 := robotgo.CaptureImg()
|
img1 := robotgo.CaptureImg()
|
||||||
path1 := "save_" + strconv.Itoa(i)
|
path1 := "save_" + strconv.Itoa(i)
|
||||||
robotgo.Save(img1, path1+".png")
|
robotgo.Save(img1, path1+".png")
|
||||||
robotgo.SaveJpeg(img1, path1+".jpeg", 50)
|
robotgo.SaveJpeg(img1, path1+".jpeg", 50)
|
||||||
|
|
||||||
img2 := robotgo.CaptureImg(10, 10, 20, 20)
|
img2 := robotgo.CaptureImg(10, 10, 20, 20)
|
||||||
robotgo.Save(img2, "test_"+strconv.Itoa(i)+".png")
|
robotgo.Save(img2, "test_"+strconv.Itoa(i)+".png")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -2,14 +2,9 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
MMBitmapRef createMMBitmap_c(
|
MMBitmapRef createMMBitmap_c(uint8_t *buffer, size_t width, size_t height,
|
||||||
uint8_t *buffer,
|
size_t bytewidth, uint8_t bitsPerPixel, uint8_t bytesPerPixel
|
||||||
size_t width,
|
) {
|
||||||
size_t height,
|
|
||||||
size_t bytewidth,
|
|
||||||
uint8_t bitsPerPixel,
|
|
||||||
uint8_t bytesPerPixel
|
|
||||||
){
|
|
||||||
MMBitmapRef bitmap = malloc(sizeof(MMBitmap));
|
MMBitmapRef bitmap = malloc(sizeof(MMBitmap));
|
||||||
if (bitmap == NULL) { return NULL; }
|
if (bitmap == NULL) { return NULL; }
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@
|
|||||||
#define bitswap16(i) bswap_16(i) /* Linux system function */
|
#define bitswap16(i) bswap_16(i) /* Linux system function */
|
||||||
#else /* Default macro */
|
#else /* Default macro */
|
||||||
#define bitswap16(i) (((uint16_t)(i) & 0xFF00) >> 8) | \
|
#define bitswap16(i) (((uint16_t)(i) & 0xFF00) >> 8) | \
|
||||||
(((uint16_t)(i) & 0x00FF) << 8)
|
(((uint16_t)(i) & 0x00FF) << 8)
|
||||||
#endif
|
#endif
|
||||||
#endif /* bitswap16 */
|
#endif /* bitswap16 */
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#define __bool_true_false_are_defined 1
|
#define __bool_true_false_are_defined 1
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
|
|
||||||
#if defined(true) || defined(false) || defined(bool)
|
#if defined(true) || defined(false) || defined(bool)
|
||||||
#error "Boolean type already defined"
|
#error "Boolean type already defined"
|
||||||
#endif
|
#endif
|
||||||
@ -21,7 +20,6 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef unsigned char bool;
|
typedef unsigned char bool;
|
||||||
|
|
||||||
#endif /* !__cplusplus */
|
#endif /* !__cplusplus */
|
||||||
|
|
||||||
#endif /* MS_STDBOOL_H */
|
#endif /* MS_STDBOOL_H */
|
||||||
|
15
base/rgb.h
15
base/rgb.h
@ -12,7 +12,6 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* RGB colors in MMBitmaps are stored as BGR for convenience in converting
|
/* RGB colors in MMBitmaps are stored as BGR for convenience in converting
|
||||||
* to/from certain formats (mainly OpenGL).
|
* to/from certain formats (mainly OpenGL).
|
||||||
*
|
*
|
||||||
@ -46,8 +45,7 @@ typedef uint32_t MMRGBHex;
|
|||||||
#define RGB_TO_HEX(red, green, blue) (((red) << 16) | ((green) << 8) | (blue))
|
#define RGB_TO_HEX(red, green, blue) (((red) << 16) | ((green) << 8) | (blue))
|
||||||
|
|
||||||
/* Convenience wrapper for MMRGBColors. */
|
/* Convenience wrapper for MMRGBColors. */
|
||||||
H_INLINE MMRGBHex hexFromMMRGB(MMRGBColor rgb)
|
H_INLINE MMRGBHex hexFromMMRGB(MMRGBColor rgb) {
|
||||||
{
|
|
||||||
return RGB_TO_HEX(rgb.red, rgb.green, rgb.blue);
|
return RGB_TO_HEX(rgb.red, rgb.green, rgb.blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,8 +54,7 @@ H_INLINE MMRGBHex hexFromMMRGB(MMRGBColor rgb)
|
|||||||
#define BLUE_FROM_HEX(hex) (hex & 0xFF)
|
#define BLUE_FROM_HEX(hex) (hex & 0xFF)
|
||||||
|
|
||||||
/* Converts hexadecimal color to MMRGBColor. */
|
/* Converts hexadecimal color to MMRGBColor. */
|
||||||
H_INLINE MMRGBColor MMRGBFromHex(MMRGBHex hex)
|
H_INLINE MMRGBColor MMRGBFromHex(MMRGBHex hex) {
|
||||||
{
|
|
||||||
MMRGBColor color;
|
MMRGBColor color;
|
||||||
color.red = RED_FROM_HEX(hex);
|
color.red = RED_FROM_HEX(hex);
|
||||||
color.green = GREEN_FROM_HEX(hex);
|
color.green = GREEN_FROM_HEX(hex);
|
||||||
@ -73,9 +70,7 @@ H_INLINE MMRGBColor MMRGBFromHex(MMRGBHex hex)
|
|||||||
/* Returns whether two colors are similar within the given range, |tolerance|.
|
/* Returns whether two colors are similar within the given range, |tolerance|.
|
||||||
* Tolerance can be in the range 0.0f - 1.0f, where 0 denotes the exact
|
* Tolerance can be in the range 0.0f - 1.0f, where 0 denotes the exact
|
||||||
* color and 1 denotes any color. */
|
* color and 1 denotes any color. */
|
||||||
H_INLINE int MMRGBColorSimilarToColor(MMRGBColor c1, MMRGBColor c2,
|
H_INLINE int MMRGBColorSimilarToColor(MMRGBColor c1, MMRGBColor c2, float tolerance) {
|
||||||
float tolerance)
|
|
||||||
{
|
|
||||||
/* Speedy case */
|
/* Speedy case */
|
||||||
if (tolerance <= 0.0f) {
|
if (tolerance <= 0.0f) {
|
||||||
return MMRGBColorEqualToColor(c1, c2);
|
return MMRGBColorEqualToColor(c1, c2);
|
||||||
@ -87,12 +82,10 @@ H_INLINE int MMRGBColorSimilarToColor(MMRGBColor c1, MMRGBColor c2,
|
|||||||
(d2 * d2) +
|
(d2 * d2) +
|
||||||
(d3 * d3)) <= (tolerance * 442.0f);
|
(d3 * d3)) <= (tolerance * 442.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Identical to MMRGBColorSimilarToColor, only for hex values. */
|
/* Identical to MMRGBColorSimilarToColor, only for hex values. */
|
||||||
H_INLINE int MMRGBHexSimilarToColor(MMRGBHex h1, MMRGBHex h2, float tolerance)
|
H_INLINE int MMRGBHexSimilarToColor(MMRGBHex h1, MMRGBHex h2, float tolerance) {
|
||||||
{
|
|
||||||
if (tolerance <= 0.0f) {
|
if (tolerance <= 0.0f) {
|
||||||
return h1 == h2;
|
return h1 == h2;
|
||||||
} else {
|
} else {
|
||||||
|
42
base/types.h
42
base/types.h
@ -8,7 +8,6 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/* Some generic, cross-platform types. */
|
/* Some generic, cross-platform types. */
|
||||||
|
|
||||||
#ifdef RobotGo_64
|
#ifdef RobotGo_64
|
||||||
typedef int64_t intptr;
|
typedef int64_t intptr;
|
||||||
typedef uint64_t uintptr;
|
typedef uint64_t uintptr;
|
||||||
@ -21,87 +20,74 @@ struct _MMPoint {
|
|||||||
size_t x;
|
size_t x;
|
||||||
size_t y;
|
size_t y;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _MMPoint MMPoint;
|
typedef struct _MMPoint MMPoint;
|
||||||
|
|
||||||
struct _MMPointInt32 {
|
struct _MMPointInt32 {
|
||||||
int32_t x;
|
int32_t x;
|
||||||
int32_t y;
|
int32_t y;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _MMPointInt32 MMPointInt32;
|
typedef struct _MMPointInt32 MMPointInt32;
|
||||||
|
|
||||||
struct _MMSize {
|
struct _MMSize {
|
||||||
size_t width;
|
size_t width;
|
||||||
size_t height;
|
size_t height;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _MMSize MMSize;
|
typedef struct _MMSize MMSize;
|
||||||
|
|
||||||
struct _MMSizeInt32 {
|
struct _MMSizeInt32 {
|
||||||
int32_t w;
|
int32_t w;
|
||||||
int32_t h;
|
int32_t h;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _MMSizeInt32 MMSizeInt32;
|
typedef struct _MMSizeInt32 MMSizeInt32;
|
||||||
|
|
||||||
|
|
||||||
struct _MMRect {
|
struct _MMRect {
|
||||||
MMPoint origin;
|
MMPoint origin;
|
||||||
MMSize size;
|
MMSize size;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _MMRect MMRect;
|
typedef struct _MMRect MMRect;
|
||||||
|
|
||||||
struct _MMRectInt32 {
|
struct _MMRectInt32 {
|
||||||
MMPointInt32 origin;
|
MMPointInt32 origin;
|
||||||
MMSizeInt32 size;
|
MMSizeInt32 size;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _MMRectInt32 MMRectInt32;
|
typedef struct _MMRectInt32 MMRectInt32;
|
||||||
|
|
||||||
H_INLINE MMPoint MMPointMake(size_t x, size_t y)
|
H_INLINE MMPoint MMPointMake(size_t x, size_t y) {
|
||||||
{
|
|
||||||
MMPoint point;
|
MMPoint point;
|
||||||
point.x = x;
|
point.x = x;
|
||||||
point.y = y;
|
point.y = y;
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
H_INLINE MMPointInt32 MMPointInt32Make(int32_t x, int32_t y)
|
H_INLINE MMPointInt32 MMPointInt32Make(int32_t x, int32_t y) {
|
||||||
{
|
|
||||||
MMPointInt32 point;
|
MMPointInt32 point;
|
||||||
point.x = x;
|
point.x = x;
|
||||||
point.y = y;
|
point.y = y;
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
H_INLINE MMSize MMSizeMake(size_t width, size_t height)
|
H_INLINE MMSize MMSizeMake(size_t width, size_t height) {
|
||||||
{
|
|
||||||
MMSize size;
|
MMSize size;
|
||||||
size.width = width;
|
size.width = width;
|
||||||
size.height = height;
|
size.height = height;
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
H_INLINE MMSizeInt32 MMSizeInt32Make(int32_t w, int32_t h)
|
H_INLINE MMSizeInt32 MMSizeInt32Make(int32_t w, int32_t h) {
|
||||||
{
|
|
||||||
MMSizeInt32 size;
|
MMSizeInt32 size;
|
||||||
size.w = w;
|
size.w = w;
|
||||||
size.h = h;
|
size.h = h;
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
H_INLINE MMRect MMRectMake(size_t x, size_t y, size_t width, size_t height)
|
H_INLINE MMRect MMRectMake(size_t x, size_t y, size_t width, size_t height) {
|
||||||
{
|
|
||||||
MMRect rect;
|
MMRect rect;
|
||||||
rect.origin = MMPointMake(x, y);
|
rect.origin = MMPointMake(x, y);
|
||||||
rect.size = MMSizeMake(width, height);
|
rect.size = MMSizeMake(width, height);
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
H_INLINE MMRectInt32 MMRectInt32Make(int32_t x, int32_t y, int32_t w, int32_t h)
|
H_INLINE MMRectInt32 MMRectInt32Make(int32_t x, int32_t y, int32_t w, int32_t h) {
|
||||||
{
|
|
||||||
MMRectInt32 rect;
|
MMRectInt32 rect;
|
||||||
rect.origin = MMPointInt32Make(x, y);
|
rect.origin = MMPointInt32Make(x, y);
|
||||||
rect.size = MMSizeInt32Make(w, h);
|
rect.size = MMSizeInt32Make(w, h);
|
||||||
@ -112,18 +98,14 @@ H_INLINE MMRectInt32 MMRectInt32Make(int32_t x, int32_t y, int32_t w, int32_t h)
|
|||||||
#define MMPointZero MMPointMake(0, 0)
|
#define MMPointZero MMPointMake(0, 0)
|
||||||
|
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
|
#define CGPointFromMMPoint(p) CGPointMake((CGFloat)(p).x, (CGFloat)(p).y)
|
||||||
|
#define MMPointFromCGPoint(p) MMPointMake((size_t)(p).x, (size_t)(p).y)
|
||||||
|
|
||||||
#define CGPointFromMMPoint(p) CGPointMake((CGFloat)(p).x, (CGFloat)(p).y)
|
#define CGPointFromMMPointInt32(p) CGPointMake((CGFloat)(p).x, (CGFloat)(p).y)
|
||||||
#define MMPointFromCGPoint(p) MMPointMake((size_t)(p).x, (size_t)(p).y)
|
#define MMPointInt32FromCGPoint(p) MMPointInt32Make((int32_t)(p).x, (int32_t)(p).y)
|
||||||
|
|
||||||
#define CGPointFromMMPointInt32(p) CGPointMake((CGFloat)(p).x, (CGFloat)(p).y)
|
|
||||||
#define MMPointInt32FromCGPoint(p) MMPointInt32Make((int32_t)(p).x, (int32_t)(p).y)
|
|
||||||
|
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
|
#define MMPointFromPOINT(p) MMPointMake((size_t)p.x, (size_t)p.y)
|
||||||
#define MMPointFromPOINT(p) MMPointMake((size_t)p.x, (size_t)p.y)
|
#define MMPointInt32FromPOINT(p) MMPointInt32Make((int32_t)p.x, (int32_t)p.y)
|
||||||
#define MMPointInt32FromPOINT(p) MMPointInt32Make((int32_t)p.x, (int32_t)p.y)
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* TYPES_H */
|
#endif /* TYPES_H */
|
||||||
|
@ -30,5 +30,4 @@
|
|||||||
// printf("%d\n", info.hWnd);
|
// printf("%d\n", info.hWnd);
|
||||||
return info.hWnd;
|
return info.hWnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
18
key/goKey.h
18
key/goKey.h
@ -172,23 +172,23 @@ int CheckKeyCodes(char* k, MMKeyCode *key){
|
|||||||
int CheckKeyFlags(char* f, MMKeyFlags* flags){
|
int CheckKeyFlags(char* f, MMKeyFlags* flags){
|
||||||
if (!flags) { return -1; }
|
if (!flags) { return -1; }
|
||||||
|
|
||||||
if ( strcmp(f, "alt") == 0 || strcmp(f, "ralt") == 0 ||
|
if (strcmp(f, "alt") == 0 || strcmp(f, "ralt") == 0 ||
|
||||||
strcmp(f, "lalt") == 0 ) {
|
strcmp(f, "lalt") == 0 ) {
|
||||||
*flags = MOD_ALT;
|
*flags = MOD_ALT;
|
||||||
}
|
}
|
||||||
else if( strcmp(f, "command") == 0 || strcmp(f, "cmd") == 0 ||
|
else if(strcmp(f, "command") == 0 || strcmp(f, "cmd") == 0 ||
|
||||||
strcmp(f, "rcmd") == 0 || strcmp(f, "lcmd") == 0 ) {
|
strcmp(f, "rcmd") == 0 || strcmp(f, "lcmd") == 0 ) {
|
||||||
*flags = MOD_META;
|
*flags = MOD_META;
|
||||||
}
|
}
|
||||||
else if( strcmp(f, "control") == 0 || strcmp(f, "ctrl") == 0 ||
|
else if(strcmp(f, "control") == 0 || strcmp(f, "ctrl") == 0 ||
|
||||||
strcmp(f, "rctrl") == 0 || strcmp(f, "lctrl") == 0 ) {
|
strcmp(f, "rctrl") == 0 || strcmp(f, "lctrl") == 0 ) {
|
||||||
*flags = MOD_CONTROL;
|
*flags = MOD_CONTROL;
|
||||||
}
|
}
|
||||||
else if( strcmp(f, "shift") == 0 || strcmp(f, "right_shift") == 0 ||
|
else if(strcmp(f, "shift") == 0 || strcmp(f, "right_shift") == 0 ||
|
||||||
strcmp(f, "rshift") == 0 || strcmp(f, "lshift") == 0 ) {
|
strcmp(f, "rshift") == 0 || strcmp(f, "lshift") == 0 ) {
|
||||||
*flags = MOD_SHIFT;
|
*flags = MOD_SHIFT;
|
||||||
}
|
}
|
||||||
else if( strcmp(f, "none") == 0 ) {
|
else if(strcmp(f, "none") == 0 ) {
|
||||||
*flags = (MMKeyFlags) MOD_NONE;
|
*flags = (MMKeyFlags) MOD_NONE;
|
||||||
} else {
|
} else {
|
||||||
return -2;
|
return -2;
|
||||||
@ -332,6 +332,7 @@ char* key_Toggles(char* k, char* keyArr[], int num) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove
|
||||||
char* key_toggle(char* k, char* d, char* akey, char* keyT){
|
char* key_toggle(char* k, char* d, char* akey, char* keyT){
|
||||||
MMKeyFlags flags = (MMKeyFlags) MOD_NONE;
|
MMKeyFlags flags = (MMKeyFlags) MOD_NONE;
|
||||||
MMKeyCode key;
|
MMKeyCode key;
|
||||||
@ -390,13 +391,6 @@ char* key_toggle(char* k, char* d, char* akey, char* keyT){
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void type_string(char *str){
|
|
||||||
typeStringDelayed(str, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void type_string_delayed(char *str, size_t cpm){
|
|
||||||
typeStringDelayed(str, cpm);
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_keyboard_delay(size_t val){
|
void set_keyboard_delay(size_t val){
|
||||||
keyboardDelay = val;
|
keyboardDelay = val;
|
||||||
|
@ -1,19 +1,16 @@
|
|||||||
#include "keycode.h"
|
#include "keycode.h"
|
||||||
|
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
|
#include <Carbon/Carbon.h> /* For kVK_ constants, and TIS functions. */
|
||||||
|
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
/* Returns string representation of key, if it is printable.
|
||||||
#include <Carbon/Carbon.h> /* For kVK_ constants, and TIS functions. */
|
* Ownership follows the Create Rule; that is, it is the caller's
|
||||||
|
* responsibility to release the returned object. */
|
||||||
/* Returns string representation of key, if it is printable.
|
CFStringRef createStringForKey(CGKeyCode keyCode);
|
||||||
* Ownership follows the Create Rule; that is, it is the caller's
|
|
||||||
* responsibility to release the returned object. */
|
|
||||||
CFStringRef createStringForKey(CGKeyCode keyCode);
|
|
||||||
|
|
||||||
MMKeyCode keyCodeForCharFallBack(const char c);
|
|
||||||
|
|
||||||
|
MMKeyCode keyCodeForCharFallBack(const char c);
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Structs to store key mappings not handled by XStringToKeysym() on some
|
* Structs to store key mappings not handled by XStringToKeysym() on some
|
||||||
* Linux systems.
|
* Linux systems.
|
||||||
@ -77,11 +74,9 @@ MMKeyCode keyCodeForChar(const char c){
|
|||||||
/* Generate table of keycodes and characters. */
|
/* Generate table of keycodes and characters. */
|
||||||
if (charToCodeDict == NULL) {
|
if (charToCodeDict == NULL) {
|
||||||
size_t i;
|
size_t i;
|
||||||
charToCodeDict = CFDictionaryCreateMutable(kCFAllocatorDefault,
|
charToCodeDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 128,
|
||||||
128,
|
&kCFCopyStringDictionaryKeyCallBacks, NULL);
|
||||||
&kCFCopyStringDictionaryKeyCallBacks,
|
if (charToCodeDict == NULL) { return K_NOT_A_KEY; }
|
||||||
NULL);
|
|
||||||
if (charToCodeDict == NULL) return K_NOT_A_KEY;
|
|
||||||
|
|
||||||
/* Loop through every keycode (0 - 127) to find its current mapping. */
|
/* Loop through every keycode (0 - 127) to find its current mapping. */
|
||||||
for (i = 0; i < 128; ++i) {
|
for (i = 0; i < 128; ++i) {
|
||||||
@ -135,7 +130,7 @@ MMKeyCode keyCodeForChar(const char c){
|
|||||||
* mapping table. */
|
* mapping table. */
|
||||||
struct XSpecialCharacterMapping* xs = XSpecialCharacterTable;
|
struct XSpecialCharacterMapping* xs = XSpecialCharacterTable;
|
||||||
while (xs->name) {
|
while (xs->name) {
|
||||||
if (c == xs->name ) {
|
if (c == xs->name) {
|
||||||
code = xs->code;
|
code = xs->code;
|
||||||
//
|
//
|
||||||
break;
|
break;
|
||||||
@ -152,34 +147,22 @@ MMKeyCode keyCodeForChar(const char c){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#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 layoutData = (CFDataRef) TISGetInputSourceProperty(
|
||||||
(CFDataRef)TISGetInputSourceProperty(currentKeyboard,
|
currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
|
||||||
kTISPropertyUnicodeKeyLayoutData);
|
|
||||||
|
|
||||||
if (layoutData == nil) { return 0; }
|
if (layoutData == nil) { return 0; }
|
||||||
|
|
||||||
const UCKeyboardLayout *keyboardLayout =
|
const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout *) CFDataGetBytePtr(layoutData);
|
||||||
(const UCKeyboardLayout *)CFDataGetBytePtr(layoutData);
|
|
||||||
|
|
||||||
UInt32 keysDown = 0;
|
UInt32 keysDown = 0;
|
||||||
UniChar chars[4];
|
UniChar chars[4];
|
||||||
UniCharCount realLength;
|
UniCharCount realLength;
|
||||||
|
|
||||||
UCKeyTranslate(keyboardLayout,
|
UCKeyTranslate(keyboardLayout, keyCode, kUCKeyActionDisplay, 0, LMGetKbdType(),
|
||||||
keyCode,
|
kUCKeyTranslateNoDeadKeysBit, &keysDown,
|
||||||
kUCKeyActionDisplay,
|
sizeof(chars) / sizeof(chars[0]), &realLength, chars);
|
||||||
0,
|
|
||||||
LMGetKbdType(),
|
|
||||||
kUCKeyTranslateNoDeadKeysBit,
|
|
||||||
&keysDown,
|
|
||||||
sizeof(chars) / sizeof(chars[0]),
|
|
||||||
&realLength,
|
|
||||||
chars);
|
|
||||||
CFRelease(currentKeyboard);
|
CFRelease(currentKeyboard);
|
||||||
|
|
||||||
return CFStringCreateWithCharacters(kCFAllocatorDefault, chars, 1);
|
return CFStringCreateWithCharacters(kCFAllocatorDefault, chars, 1);
|
||||||
|
@ -17,7 +17,6 @@ extern "C"
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MOD_NONE = 0,
|
MOD_NONE = 0,
|
||||||
MOD_META = kCGEventFlagMaskCommand,
|
MOD_META = kCGEventFlagMaskCommand,
|
||||||
@ -25,9 +24,7 @@ extern "C"
|
|||||||
MOD_CONTROL = kCGEventFlagMaskControl,
|
MOD_CONTROL = kCGEventFlagMaskControl,
|
||||||
MOD_SHIFT = kCGEventFlagMaskShift
|
MOD_SHIFT = kCGEventFlagMaskShift
|
||||||
} MMKeyFlags;
|
} MMKeyFlags;
|
||||||
|
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
|
|
||||||
enum _MMKeyFlags {
|
enum _MMKeyFlags {
|
||||||
MOD_NONE = 0,
|
MOD_NONE = 0,
|
||||||
MOD_META = Mod4Mask,
|
MOD_META = Mod4Mask,
|
||||||
@ -37,9 +34,7 @@ extern "C"
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef unsigned int MMKeyFlags;
|
typedef unsigned int MMKeyFlags;
|
||||||
|
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
|
|
||||||
enum _MMKeyFlags {
|
enum _MMKeyFlags {
|
||||||
MOD_NONE = 0,
|
MOD_NONE = 0,
|
||||||
/* These are already defined by the Win32 API */
|
/* These are already defined by the Win32 API */
|
||||||
@ -50,7 +45,6 @@ extern "C"
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef unsigned int MMKeyFlags;
|
typedef unsigned int MMKeyFlags;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(IS_WINDOWS)
|
#if defined(IS_WINDOWS)
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#include "../base/microsleep.h"
|
#include "../base/microsleep.h"
|
||||||
|
|
||||||
#include <ctype.h> /* For isupper() */
|
#include <ctype.h> /* For isupper() */
|
||||||
|
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
#include <ApplicationServices/ApplicationServices.h>
|
#include <ApplicationServices/ApplicationServices.h>
|
||||||
#import <IOKit/hidsystem/IOHIDLib.h>
|
#import <IOKit/hidsystem/IOHIDLib.h>
|
||||||
@ -18,34 +17,29 @@
|
|||||||
#define WIN32_KEY_EVENT_WAIT(key, flags) \
|
#define WIN32_KEY_EVENT_WAIT(key, flags) \
|
||||||
(win32KeyEvent(key, flags), Sleep(DEADBEEF_RANDRANGE(0, 1)))
|
(win32KeyEvent(key, flags), Sleep(DEADBEEF_RANDRANGE(0, 1)))
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
#define X_KEY_EVENT(display, key, is_press) \
|
#define X_KEY_EVENT(display, key, is_press) ( \
|
||||||
(XTestFakeKeyEvent(display, \
|
XTestFakeKeyEvent(display, XKeysymToKeycode(display, key), is_press, CurrentTime), \
|
||||||
XKeysymToKeycode(display, key), \
|
XSync(display, false))
|
||||||
is_press, CurrentTime), \
|
#define X_KEY_EVENT_WAIT(display, key, is_press) ( \
|
||||||
XSync(display, false))
|
X_KEY_EVENT(display, key, is_press), microsleep(DEADBEEF_UNIFORM(0.0, 0.5)))
|
||||||
#define X_KEY_EVENT_WAIT(display, key, is_press) \
|
|
||||||
(X_KEY_EVENT(display, key, is_press), \
|
|
||||||
microsleep(DEADBEEF_UNIFORM(0.0, 0.5)))
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
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;
|
||||||
|
|
||||||
if (!sEventDrvrRef) {
|
if (!sEventDrvrRef) {
|
||||||
kr = IOMasterPort( bootstrap_port, &masterPort );
|
kr = IOMasterPort(bootstrap_port, &masterPort);
|
||||||
assert(KERN_SUCCESS == kr);
|
assert(KERN_SUCCESS == kr);
|
||||||
kr = IOServiceGetMatchingServices(masterPort,
|
kr = IOServiceGetMatchingServices(masterPort, IOServiceMatching(kIOHIDSystemClass), &iter);
|
||||||
IOServiceMatching( kIOHIDSystemClass), &iter );
|
|
||||||
assert(KERN_SUCCESS == kr);
|
assert(KERN_SUCCESS == kr);
|
||||||
|
|
||||||
service = IOIteratorNext( iter );
|
service = IOIteratorNext(iter);
|
||||||
assert(service);
|
assert(service);
|
||||||
|
|
||||||
kr = IOServiceOpen(service,
|
kr = IOServiceOpen(service, mach_task_self(), kIOHIDParamConnectType, &sEventDrvrRef);
|
||||||
mach_task_self(), kIOHIDParamConnectType, &sEventDrvrRef );
|
|
||||||
assert(KERN_SUCCESS == kr);
|
assert(KERN_SUCCESS == kr);
|
||||||
|
|
||||||
IOObjectRelease(service);
|
IOObjectRelease(service);
|
||||||
@ -56,7 +50,7 @@ static io_connect_t _getAuxiliaryKeyDriver(void){
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(IS_WINDOWS)
|
#if defined(IS_WINDOWS)
|
||||||
void win32KeyEvent(int key, MMKeyFlags flags){
|
void win32KeyEvent(int key, MMKeyFlags flags) {
|
||||||
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 */
|
||||||
@ -103,7 +97,6 @@ void win32KeyEvent(int key, MMKeyFlags flags){
|
|||||||
// if ( flags & KEYEVENTF_KEYUP ) {
|
// if ( flags & KEYEVENTF_KEYUP ) {
|
||||||
// scan |= 0x80;
|
// scan |= 0x80;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// keybd_event(key, scan, flags, 0);
|
// keybd_event(key, scan, flags, 0);
|
||||||
|
|
||||||
INPUT keyInput;
|
INPUT keyInput;
|
||||||
@ -118,12 +111,12 @@ void win32KeyEvent(int key, MMKeyFlags flags){
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void toggleKeyCode(MMKeyCode code, const bool down, MMKeyFlags flags){
|
void toggleKeyCode(MMKeyCode code, const bool down, MMKeyFlags flags) {
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
/* The media keys all have 1000 added to them to help us detect them. */
|
/* The media keys all have 1000 added to them to help us detect them. */
|
||||||
if (code >= 1000) {
|
if (code >= 1000) {
|
||||||
code = code - 1000; /* Get the real keycode. */
|
code = code - 1000; /* Get the real keycode. */
|
||||||
NXEventData event;
|
NXEventData event;
|
||||||
kern_return_t kr;
|
kern_return_t kr;
|
||||||
|
|
||||||
IOGPoint loc = { 0, 0 };
|
IOGPoint loc = { 0, 0 };
|
||||||
@ -133,12 +126,11 @@ void toggleKeyCode(MMKeyCode code, const bool down, MMKeyFlags flags){
|
|||||||
event.compound.subType = NX_SUBTYPE_AUX_CONTROL_BUTTONS;
|
event.compound.subType = NX_SUBTYPE_AUX_CONTROL_BUTTONS;
|
||||||
event.compound.misc.L[0] = evtInfo;
|
event.compound.misc.L[0] = evtInfo;
|
||||||
|
|
||||||
kr = IOHIDPostEvent( _getAuxiliaryKeyDriver(),
|
kr = IOHIDPostEvent(_getAuxiliaryKeyDriver(),
|
||||||
NX_SYSDEFINED, loc, &event, kNXEventDataVersion, 0, FALSE );
|
NX_SYSDEFINED, loc, &event, kNXEventDataVersion, 0, FALSE);
|
||||||
assert( KERN_SUCCESS == kr );
|
assert(KERN_SUCCESS == kr);
|
||||||
} else {
|
} else {
|
||||||
CGEventRef keyEvent = CGEventCreateKeyboardEvent(NULL,
|
CGEventRef keyEvent = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)code, down);
|
||||||
(CGKeyCode)code, down);
|
|
||||||
assert(keyEvent != NULL);
|
assert(keyEvent != NULL);
|
||||||
|
|
||||||
CGEventSetType(keyEvent, down ? kCGEventKeyDown : kCGEventKeyUp);
|
CGEventSetType(keyEvent, down ? kCGEventKeyDown : kCGEventKeyUp);
|
||||||
@ -269,13 +261,11 @@ void toggleUnicode(UniChar ch, const bool down){
|
|||||||
XFlush(dpy);
|
XFlush(dpy);
|
||||||
|
|
||||||
KeyCode code = XKeysymToKeycode(dpy, sym);
|
KeyCode code = XKeysymToKeycode(dpy, sym);
|
||||||
|
|
||||||
XTestFakeKeyEvent(dpy, code, True, 1);
|
XTestFakeKeyEvent(dpy, code, True, 1);
|
||||||
XTestFakeKeyEvent(dpy, code, False, 1);
|
XTestFakeKeyEvent(dpy, code, False, 1);
|
||||||
|
|
||||||
XFlush(dpy);
|
XFlush(dpy);
|
||||||
XCloseDisplay(dpy);
|
XCloseDisplay(dpy);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -313,52 +303,4 @@ void unicodeType(const unsigned value){
|
|||||||
microsleep(5.0);
|
microsleep(5.0);
|
||||||
toggleUniKey(value, false);
|
toggleUniKey(value, false);
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
// todo: removed
|
|
||||||
void typeStringDelayed(const char *str, const unsigned cpm){
|
|
||||||
|
|
||||||
/* Characters per second */
|
|
||||||
const double cps = (double)cpm / 60.0;
|
|
||||||
|
|
||||||
/* Average milli-seconds per character */
|
|
||||||
const double mspc = (cps == 0.0) ? 0.0 : 1000.0 / cps;
|
|
||||||
|
|
||||||
unsigned long n;
|
|
||||||
unsigned short c;
|
|
||||||
unsigned short c1;
|
|
||||||
unsigned short c2;
|
|
||||||
unsigned short c3;
|
|
||||||
|
|
||||||
while (*str != '\0') {
|
|
||||||
c = *str++;
|
|
||||||
|
|
||||||
// warning, the following utf8 decoder
|
|
||||||
// doesn't perform validation
|
|
||||||
if (c <= 0x7F) {
|
|
||||||
// 0xxxxxxx one byte
|
|
||||||
n = c;
|
|
||||||
} else if ((c & 0xE0) == 0xC0) {
|
|
||||||
// 110xxxxx two bytes
|
|
||||||
c1 = (*str++) & 0x3F;
|
|
||||||
n = ((c & 0x1F) << 6) | c1;
|
|
||||||
} else if ((c & 0xF0) == 0xE0) {
|
|
||||||
// 1110xxxx three bytes
|
|
||||||
c1 = (*str++) & 0x3F;
|
|
||||||
c2 = (*str++) & 0x3F;
|
|
||||||
n = ((c & 0x0F) << 12) | (c1 << 6) | c2;
|
|
||||||
} else if ((c & 0xF8) == 0xF0) {
|
|
||||||
// 11110xxx four bytes
|
|
||||||
c1 = (*str++) & 0x3F;
|
|
||||||
c2 = (*str++) & 0x3F;
|
|
||||||
c3 = (*str++) & 0x3F;
|
|
||||||
n = ((c & 0x07) << 18) | (c1 << 12) | (c2 << 6) | c3;
|
|
||||||
}
|
|
||||||
|
|
||||||
unicodeType(n);
|
|
||||||
|
|
||||||
if (mspc > 0) {
|
|
||||||
microsleep(mspc + (DEADBEEF_UNIFORM(0.0, 0.5)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -30,18 +30,15 @@
|
|||||||
|
|
||||||
#define MMMouseDownToCGEventType(button) \
|
#define MMMouseDownToCGEventType(button) \
|
||||||
((button) == (LEFT_BUTTON) ? kCGEventLeftMouseDown \
|
((button) == (LEFT_BUTTON) ? kCGEventLeftMouseDown \
|
||||||
: ((button) == RIGHT_BUTTON ? kCGEventRightMouseDown \
|
: ((button) == RIGHT_BUTTON ? kCGEventRightMouseDown : kCGEventOtherMouseDown))
|
||||||
: kCGEventOtherMouseDown))
|
|
||||||
|
|
||||||
#define MMMouseUpToCGEventType(button) \
|
#define MMMouseUpToCGEventType(button) \
|
||||||
((button) == LEFT_BUTTON ? kCGEventLeftMouseUp \
|
((button) == LEFT_BUTTON ? kCGEventLeftMouseUp \
|
||||||
: ((button) == RIGHT_BUTTON ? kCGEventRightMouseUp \
|
: ((button) == RIGHT_BUTTON ? kCGEventRightMouseUp : kCGEventOtherMouseUp))
|
||||||
: kCGEventOtherMouseUp))
|
|
||||||
|
|
||||||
#define MMMouseDragToCGEventType(button) \
|
#define MMMouseDragToCGEventType(button) \
|
||||||
((button) == LEFT_BUTTON ? kCGEventLeftMouseDragged \
|
((button) == LEFT_BUTTON ? kCGEventLeftMouseDragged \
|
||||||
: ((button) == RIGHT_BUTTON ? kCGEventRightMouseDragged \
|
: ((button) == RIGHT_BUTTON ? kCGEventRightMouseDragged : kCGEventOtherMouseDragged))
|
||||||
: kCGEventOtherMouseDragged))
|
|
||||||
|
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
|
|
||||||
@ -50,13 +47,11 @@
|
|||||||
|
|
||||||
#define MMMouseUpToMEventF(button) \
|
#define MMMouseUpToMEventF(button) \
|
||||||
((button) == LEFT_BUTTON ? MOUSEEVENTF_LEFTUP \
|
((button) == LEFT_BUTTON ? MOUSEEVENTF_LEFTUP \
|
||||||
: ((button) == RIGHT_BUTTON ? MOUSEEVENTF_RIGHTUP \
|
: ((button) == RIGHT_BUTTON ? MOUSEEVENTF_RIGHTUP : MOUSEEVENTF_MIDDLEUP))
|
||||||
: MOUSEEVENTF_MIDDLEUP))
|
|
||||||
|
|
||||||
#define MMMouseDownToMEventF(button) \
|
#define MMMouseDownToMEventF(button) \
|
||||||
((button) == LEFT_BUTTON ? MOUSEEVENTF_LEFTDOWN \
|
((button) == LEFT_BUTTON ? MOUSEEVENTF_LEFTDOWN \
|
||||||
: ((button) == RIGHT_BUTTON ? MOUSEEVENTF_RIGHTDOWN \
|
: ((button) == RIGHT_BUTTON ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_MIDDLEDOWN))
|
||||||
: MOUSEEVENTF_MIDDLEDOWN))
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -158,8 +153,8 @@ MMPointInt32 getMousePos(){
|
|||||||
unsigned int more_garbage;
|
unsigned int more_garbage;
|
||||||
|
|
||||||
Display *display = XGetMainDisplay();
|
Display *display = XGetMainDisplay();
|
||||||
XQueryPointer(display, XDefaultRootWindow(display), &garb1, &garb2,
|
XQueryPointer(display, XDefaultRootWindow(display), &garb1, &garb2, &x, &y,
|
||||||
&x, &y, &garb_x, &garb_y, &more_garbage);
|
&garb_x, &garb_y, &more_garbage);
|
||||||
|
|
||||||
return MMPointInt32Make(x, y);
|
return MMPointInt32Make(x, y);
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
@ -179,8 +174,7 @@ void toggleMouse(bool down, MMMouseButton button){
|
|||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
const CGPoint currentPos = CGPointFromMMPoint(getMousePos());
|
const CGPoint currentPos = CGPointFromMMPoint(getMousePos());
|
||||||
const CGEventType mouseType = MMMouseToCGEventType(down, button);
|
const CGEventType mouseType = MMMouseToCGEventType(down, button);
|
||||||
CGEventRef event = CGEventCreateMouseEvent(NULL,
|
CGEventRef event = CGEventCreateMouseEvent(NULL, mouseType, currentPos, (CGMouseButton)button);
|
||||||
mouseType, currentPos, (CGMouseButton)button);
|
|
||||||
|
|
||||||
CGEventPost(kCGSessionEventTap, event);
|
CGEventPost(kCGSessionEventTap, event);
|
||||||
CFRelease(event);
|
CFRelease(event);
|
||||||
@ -215,32 +209,26 @@ 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 = CGPointFromMMPoint(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);
|
||||||
|
|
||||||
CGEventRef event = CGEventCreateMouseEvent(
|
CGEventRef event = CGEventCreateMouseEvent(NULL, mouseTypeDown, currentPos, kCGMouseButtonLeft);
|
||||||
NULL, mouseTypeDown, currentPos, kCGMouseButtonLeft);
|
|
||||||
|
|
||||||
/* Set event to double click. */
|
/* Set event to double click. */
|
||||||
CGEventSetIntegerValueField(event, kCGMouseEventClickState, 2);
|
CGEventSetIntegerValueField(event, kCGMouseEventClickState, 2);
|
||||||
|
|
||||||
CGEventPost(kCGHIDEventTap, event);
|
CGEventPost(kCGHIDEventTap, event);
|
||||||
|
|
||||||
CGEventSetType(event, mouseTypeUP);
|
CGEventSetType(event, mouseTypeUP);
|
||||||
CGEventPost(kCGHIDEventTap, event);
|
CGEventPost(kCGHIDEventTap, event);
|
||||||
|
|
||||||
CFRelease(event);
|
CFRelease(event);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/* Double click for everything else. */
|
/* Double click for everything else. */
|
||||||
clickMouse(button);
|
clickMouse(button);
|
||||||
microsleep(200);
|
microsleep(200);
|
||||||
clickMouse(button);
|
clickMouse(button);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,13 +260,9 @@ void scrollMouse(int scrollMagnitude, MMMouseWheelDirection scrollDirection){
|
|||||||
/* Make scroll magnitude negative if we're scrolling down. */
|
/* Make scroll magnitude negative if we're scrolling down. */
|
||||||
cleanScrollMagnitude = cleanScrollMagnitude * scrollDirection;
|
cleanScrollMagnitude = cleanScrollMagnitude * scrollDirection;
|
||||||
|
|
||||||
event = CGEventCreateScrollWheelEvent(NULL,
|
event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitLine, wheel, cleanScrollMagnitude, 0);
|
||||||
kCGScrollEventUnitLine, wheel, cleanScrollMagnitude, 0);
|
|
||||||
|
|
||||||
CGEventPost(kCGHIDEventTap, event);
|
CGEventPost(kCGHIDEventTap, event);
|
||||||
|
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
|
|
||||||
int x;
|
int x;
|
||||||
int dir = 4; /* Button 4 is up, 5 is down. */
|
int dir = 4; /* Button 4 is up, 5 is down. */
|
||||||
Display *display = XGetMainDisplay();
|
Display *display = XGetMainDisplay();
|
||||||
@ -293,9 +277,7 @@ void scrollMouse(int scrollMagnitude, MMMouseWheelDirection scrollDirection){
|
|||||||
}
|
}
|
||||||
|
|
||||||
XSync(display, false);
|
XSync(display, false);
|
||||||
|
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
|
|
||||||
mouseScrollInput.type = INPUT_MOUSE;
|
mouseScrollInput.type = INPUT_MOUSE;
|
||||||
mouseScrollInput.mi.dx = 0;
|
mouseScrollInput.mi.dx = 0;
|
||||||
mouseScrollInput.mi.dy = 0;
|
mouseScrollInput.mi.dy = 0;
|
||||||
@ -305,7 +287,6 @@ void scrollMouse(int scrollMagnitude, MMMouseWheelDirection scrollDirection){
|
|||||||
mouseScrollInput.mi.mouseData = WHEEL_DELTA * scrollDirection * cleanScrollMagnitude;
|
mouseScrollInput.mi.mouseData = WHEEL_DELTA * scrollDirection * cleanScrollMagnitude;
|
||||||
|
|
||||||
SendInput(1, &mouseScrollInput, sizeof(mouseScrollInput));
|
SendInput(1, &mouseScrollInput, sizeof(mouseScrollInput));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,16 +303,12 @@ void scrollMouseXY(int x, int y) {
|
|||||||
|
|
||||||
/* Set up the OS specific solution */
|
/* Set up the OS specific solution */
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
|
|
||||||
CGEventRef event;
|
CGEventRef event;
|
||||||
|
|
||||||
event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 2, y, x);
|
event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 2, y, x);
|
||||||
CGEventPost(kCGHIDEventTap, event);
|
CGEventPost(kCGHIDEventTap, event);
|
||||||
|
|
||||||
CFRelease(event);
|
CFRelease(event);
|
||||||
|
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
|
|
||||||
int ydir = 4; /* Button 4 is up, 5 is down. */
|
int ydir = 4; /* Button 4 is up, 5 is down. */
|
||||||
int xdir = 6;
|
int xdir = 6;
|
||||||
Display *display = XGetMainDisplay();
|
Display *display = XGetMainDisplay();
|
||||||
@ -355,9 +332,7 @@ void scrollMouseXY(int x, int y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
XSync(display, false);
|
XSync(display, false);
|
||||||
|
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
|
|
||||||
mouseScrollInputH.type = INPUT_MOUSE;
|
mouseScrollInputH.type = INPUT_MOUSE;
|
||||||
mouseScrollInputH.mi.dx = 0;
|
mouseScrollInputH.mi.dx = 0;
|
||||||
mouseScrollInputH.mi.dy = 0;
|
mouseScrollInputH.mi.dy = 0;
|
||||||
@ -408,9 +383,7 @@ bool smoothlyMoveMouse(MMPointInt32 endPoint, double lowSpeed, double highSpeed)
|
|||||||
double velo_x = 0.0, velo_y = 0.0;
|
double velo_x = 0.0, velo_y = 0.0;
|
||||||
double distance;
|
double distance;
|
||||||
|
|
||||||
while ((distance =
|
while ((distance =crude_hypot((double)pos.x - endPoint.x, (double)pos.y - endPoint.y)) > 1.0) {
|
||||||
crude_hypot((double)pos.x - endPoint.x, (double)pos.y - endPoint.y)
|
|
||||||
) > 1.0) {
|
|
||||||
|
|
||||||
double gravity = DEADBEEF_UNIFORM(5.0, 500.0);
|
double gravity = DEADBEEF_UNIFORM(5.0, 500.0);
|
||||||
// double gravity = DEADBEEF_UNIFORM(lowSpeed, highSpeed);
|
// double gravity = DEADBEEF_UNIFORM(lowSpeed, highSpeed);
|
||||||
|
19
robotgo.go
19
robotgo.go
@ -1136,25 +1136,6 @@ func PasteStr(str string) string {
|
|||||||
return KeyTap("v", "control")
|
return KeyTap("v", "control")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the TypeStr(),
|
|
||||||
//
|
|
||||||
// TypeString send a string, support unicode(no linux support)
|
|
||||||
// TypeStr(string: The string to send), Wno-deprecated
|
|
||||||
//
|
|
||||||
// This function will be removed in version v1.0.0
|
|
||||||
func TypeString(str string, delay ...int) {
|
|
||||||
tt.Drop("TypeString", "TypeStr")
|
|
||||||
var cdelay C.size_t
|
|
||||||
cstr := C.CString(str)
|
|
||||||
if len(delay) > 0 {
|
|
||||||
cdelay = C.size_t(delay[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
C.type_string_delayed(cstr, cdelay)
|
|
||||||
|
|
||||||
C.free(unsafe.Pointer(cstr))
|
|
||||||
}
|
|
||||||
|
|
||||||
// TypeStrDelay type string delayed
|
// TypeStrDelay type string delayed
|
||||||
func TypeStrDelay(str string, delay int) {
|
func TypeStrDelay(str string, delay int) {
|
||||||
TypeStr(str)
|
TypeStr(str)
|
||||||
|
@ -37,13 +37,10 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRectInt32 rect, int32_t display_id)
|
|||||||
|
|
||||||
bufferSize = CFDataGetLength(imageData);
|
bufferSize = CFDataGetLength(imageData);
|
||||||
buffer = malloc(bufferSize);
|
buffer = malloc(bufferSize);
|
||||||
|
|
||||||
CFDataGetBytes(imageData, CFRangeMake(0, bufferSize), buffer);
|
CFDataGetBytes(imageData, CFRangeMake(0, bufferSize), buffer);
|
||||||
|
|
||||||
bitmap = createMMBitmap_c(buffer,
|
bitmap = createMMBitmap_c(buffer, CGImageGetWidth(image), CGImageGetHeight(image),
|
||||||
CGImageGetWidth(image), CGImageGetHeight(image),
|
CGImageGetBytesPerRow(image), CGImageGetBitsPerPixel(image),CGImageGetBitsPerPixel(image) / 8);
|
||||||
CGImageGetBytesPerRow(image), CGImageGetBitsPerPixel(image),
|
|
||||||
CGImageGetBitsPerPixel(image) / 8);
|
|
||||||
|
|
||||||
CFRelease(imageData);
|
CFRelease(imageData);
|
||||||
CGImageRelease(image);
|
CGImageRelease(image);
|
||||||
@ -58,16 +55,15 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRectInt32 rect, int32_t display_id)
|
|||||||
display = XGetMainDisplay();
|
display = XGetMainDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
XImage *image = XGetImage(display, XDefaultRootWindow(display),
|
XImage *image = XGetImage(display, XDefaultRootWindow(display),
|
||||||
(int)rect.origin.x, (int)rect.origin.y,
|
(int)rect.origin.x, (int)rect.origin.y,
|
||||||
(unsigned int)rect.size.w, (unsigned int)rect.size.h,
|
(unsigned int)rect.size.w, (unsigned int)rect.size.h, AllPlanes, ZPixmap);
|
||||||
AllPlanes, ZPixmap);
|
|
||||||
XCloseDisplay(display);
|
XCloseDisplay(display);
|
||||||
if (image == NULL) { return NULL; }
|
if (image == NULL) { return NULL; }
|
||||||
|
|
||||||
bitmap = createMMBitmap_c((uint8_t *)image->data,
|
bitmap = createMMBitmap_c((uint8_t *)image->data,
|
||||||
rect.size.w, rect.size.h, (size_t)image->bytes_per_line,
|
rect.size.w, rect.size.h, (size_t)image->bytes_per_line,
|
||||||
(uint8_t)image->bits_per_pixel, (uint8_t)image->bits_per_pixel / 8);
|
(uint8_t)image->bits_per_pixel, (uint8_t)image->bits_per_pixel / 8);
|
||||||
image->data = NULL; /* Steal ownership of bitmap data so we don't have to copy it. */
|
image->data = NULL; /* Steal ownership of bitmap data so we don't have to copy it. */
|
||||||
XDestroyImage(image);
|
XDestroyImage(image);
|
||||||
|
|
||||||
@ -103,9 +99,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. */
|
||||||
if ((screenMem = CreateCompatibleDC(screen)) == NULL ||
|
if ((screenMem = CreateCompatibleDC(screen)) == NULL || SelectObject(screenMem, dib) == NULL ||
|
||||||
SelectObject(screenMem, dib) == NULL ||
|
!BitBlt(screenMem, (int)0, (int)0, (int)rect.size.w, (int)rect.size.h,
|
||||||
!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)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@ -118,7 +113,7 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRectInt32 rect, int32_t display_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bitmap = createMMBitmap_c(NULL, rect.size.w, rect.size.h, 4 * rect.size.w,
|
bitmap = createMMBitmap_c(NULL, rect.size.w, rect.size.h, 4 * rect.size.w,
|
||||||
(uint8_t)bi.bmiHeader.biBitCount, 4);
|
(uint8_t)bi.bmiHeader.biBitCount, 4);
|
||||||
|
|
||||||
/* Copy the data to our pixel buffer. */
|
/* Copy the data to our pixel buffer. */
|
||||||
if (bitmap != NULL) {
|
if (bitmap != NULL) {
|
||||||
|
Loading…
Reference in New Issue
Block a user