From b910e7e514f9a67af00453d9040482ddfd0a072c Mon Sep 17 00:00:00 2001 From: Siggi Duenkel Date: Fri, 29 Apr 2016 22:55:49 +0200 Subject: [PATCH 1/4] add insert-key --- src/keycode.h | 6 ++-- src/robotjs.cc | 87 +++++++++++++++++++++++++------------------------- 2 files changed, 48 insertions(+), 45 deletions(-) diff --git a/src/keycode.h b/src/keycode.h index 71849937..4ae773d7 100644 --- a/src/keycode.h +++ b/src/keycode.h @@ -5,7 +5,7 @@ #include "os.h" #ifdef __cplusplus -extern "C" +extern "C" { #endif @@ -14,7 +14,7 @@ extern "C" #include /* Really only need */ #include #import - + enum _MMKeyCode { K_NOT_A_KEY = 9999, K_BACKSPACE = kVK_Delete, @@ -48,6 +48,7 @@ enum _MMKeyCode { K_SHIFT = kVK_Shift, K_CAPSLOCK = kVK_CapsLock, K_SPACE = kVK_Space, + K_INSERT = kVK_Insert, K_PRINTSCREEN = K_NOT_A_KEY, K_AUDIO_VOLUME_MUTE = 1007, @@ -170,6 +171,7 @@ enum _MMKeyCode { K_CAPSLOCK = VK_CAPITAL, K_SPACE = VK_SPACE, K_PRINTSCREEN = VK_SNAPSHOT, + K_INSERT = VK_INSERT, K_AUDIO_VOLUME_MUTE = VK_VOLUME_MUTE, K_AUDIO_VOLUME_DOWN = VK_VOLUME_DOWN, diff --git a/src/robotjs.cc b/src/robotjs.cc index 93d0d55e..e967f829 100644 --- a/src/robotjs.cc +++ b/src/robotjs.cc @@ -18,8 +18,8 @@ int mouseDelay = 10; int keyboardDelay = 10; /* - __ __ -| \/ | ___ _ _ ___ ___ + __ __ +| \/ | ___ _ _ ___ ___ | |\/| |/ _ \| | | / __|/ _ \ | | | | (_) | |_| \__ \ __/ |_| |_|\___/ \__,_|___/\___| @@ -238,21 +238,21 @@ NAN_METHOD(setMouseDelay) info.GetReturnValue().Set(Nan::New(1)); } -NAN_METHOD(scrollMouse) +NAN_METHOD(scrollMouse) { Nan::HandleScope scope; //Get the values of magnitude and direction from the arguments list. - if(info.Length() == 2) + if(info.Length() == 2) { int scrollMagnitude = info[0]->Int32Value(); char *s; Nan::Utf8String sstr(info[1]); s = *sstr; - + MMMouseWheelDirection scrollDirection; - + if (strcmp(s, "up") == 0) { scrollDirection = DIRECTION_UP; @@ -265,26 +265,26 @@ NAN_METHOD(scrollMouse) { return Nan::ThrowError("Invalid scroll direction specified."); } - + scrollMouse(scrollMagnitude, scrollDirection); microsleep(mouseDelay); - + info.GetReturnValue().Set(Nan::New(1)); - } - else + } + else { return Nan::ThrowError("Invalid number of arguments."); } } /* - _ __ _ _ + _ __ _ _ | |/ /___ _ _| |__ ___ __ _ _ __ __| | | ' // _ \ | | | '_ \ / _ \ / _` | '__/ _` | | . \ __/ |_| | |_) | (_) | (_| | | | (_| | |_|\_\___|\__, |_.__/ \___/ \__,_|_| \__,_| - |___/ + |___/ */ -struct KeyNames +struct KeyNames { const char* name; MMKeyCode key; @@ -323,7 +323,8 @@ static KeyNames key_names[] = { "shift", K_SHIFT }, { "space", K_SPACE }, { "printscreen", K_PRINTSCREEN }, - + { "insert", K_INSERT }, + { "audio_mute", K_AUDIO_VOLUME_MUTE }, { "audio_vol_down", K_AUDIO_VOLUME_DOWN }, { "audio_vol_up", K_AUDIO_VOLUME_UP }, @@ -336,7 +337,7 @@ static KeyNames key_names[] = { "audio_forward", K_AUDIO_FORWARD }, { "audio_repeat", K_AUDIO_REPEAT }, { "audio_random", K_AUDIO_RANDOM }, - + { "lights_mon_up", K_LIGHTS_MON_UP }, { "lights_mon_down", K_LIGHTS_MON_DOWN }, { "lights_kbd_toggle",K_LIGHTS_KBD_TOGGLE }, @@ -359,7 +360,7 @@ int CheckKeyCodes(char* k, MMKeyCode *key) *key = K_NOT_A_KEY; KeyNames* kn = key_names; - while (kn->name) + while (kn->name) { if (strcmp(k, kn->name) == 0) { @@ -369,7 +370,7 @@ int CheckKeyCodes(char* k, MMKeyCode *key) kn++; } - if (*key == K_NOT_A_KEY) + if (*key == K_NOT_A_KEY) { return -2; } @@ -577,9 +578,9 @@ NAN_METHOD(typeStringDelayed) { char *str; Nan::Utf8String string(info[0]); - + str = *string; - + size_t cpm = info[1]->Int32Value(); typeStringDelayed(str, cpm); @@ -600,12 +601,12 @@ NAN_METHOD(setKeyboardDelay) } /* - ____ - / ___| ___ _ __ ___ ___ _ __ - \___ \ / __| '__/ _ \/ _ \ '_ \ + ____ + / ___| ___ _ __ ___ ___ _ __ + \___ \ / __| '__/ _ \/ _ \ '_ \ ___) | (__| | | __/ __/ | | | |____/ \___|_| \___|\___|_| |_| - + */ /** @@ -626,7 +627,7 @@ NAN_METHOD(getPixelColor) { return Nan::ThrowError("Invalid number of arguments."); } - + MMBitmapRef bitmap; MMRGBHex color; @@ -641,9 +642,9 @@ NAN_METHOD(getPixelColor) bitmap = copyMMBitmapFromDisplayInRect(MMRectMake(x, y, 1, 1)); color = MMRGBHexAtPoint(bitmap, 0, 0); - + char hex[7]; - + padHex(color, hex); destroyMMBitmap(bitmap); @@ -665,18 +666,18 @@ NAN_METHOD(getScreenSize) info.GetReturnValue().Set(obj); } -NAN_METHOD(captureScreen) +NAN_METHOD(captureScreen) { size_t x; size_t y; size_t w; size_t h; - - //If user has provided screen coords, use them! + + //If user has provided screen coords, use them! if (info.Length() == 4) { //TODO: Make sure requested coords are within the screen bounds, or we get a seg fault. - // An error message is much nicer! + // An error message is much nicer! x = info[0]->Int32Value(); y = info[1]->Int32Value(); @@ -688,15 +689,15 @@ NAN_METHOD(captureScreen) //We're getting the full screen. x = 0; y = 0; - + //Get screen size. MMSize displaySize = getMainDisplaySize(); w = displaySize.width; h = displaySize.height; } - + MMBitmapRef bitmap = copyMMBitmapFromDisplayInRect(MMRectMake(x, y, w, h)); - + uint32_t bufferSize = bitmap->bytewidth * bitmap->height; Local buffer = Nan::NewBuffer((char*)bitmap->imageBuffer, bufferSize, destroyMMBitmapBuffer, NULL).ToLocalChecked(); @@ -707,17 +708,17 @@ NAN_METHOD(captureScreen) Nan::Set(obj, Nan::New("bitsPerPixel").ToLocalChecked(), Nan::New(bitmap->bitsPerPixel)); Nan::Set(obj, Nan::New("bytesPerPixel").ToLocalChecked(), Nan::New(bitmap->bytesPerPixel)); Nan::Set(obj, Nan::New("image").ToLocalChecked(), buffer); - + info.GetReturnValue().Set(obj); } /* - ____ _ _ -| __ )(_) |_ _ __ ___ __ _ _ __ -| _ \| | __| '_ ` _ \ / _` | '_ \ + ____ _ _ +| __ )(_) |_ _ __ ___ __ _ _ __ +| _ \| | __| '_ ` _ \ / _` | '_ \ | |_) | | |_| | | | | | (_| | |_) | -|____/|_|\__|_| |_| |_|\__,_| .__/ - |_| +|____/|_|\__|_| |_| |_|\__,_| .__/ + |_| */ class BMP @@ -732,7 +733,7 @@ class BMP }; //Convert object from Javascript to a C++ class (BMP). -BMP buildBMP(Local info) +BMP buildBMP(Local info) { Local obj = Nan::To(info).ToLocalChecked(); @@ -804,7 +805,7 @@ NAN_MODULE_INIT(InitAll) Nan::Set(target, Nan::New("mouseToggle").ToLocalChecked(), Nan::GetFunction(Nan::New(mouseToggle)).ToLocalChecked()); - + Nan::Set(target, Nan::New("scrollMouse").ToLocalChecked(), Nan::GetFunction(Nan::New(scrollMouse)).ToLocalChecked()); @@ -831,10 +832,10 @@ NAN_MODULE_INIT(InitAll) Nan::Set(target, Nan::New("getScreenSize").ToLocalChecked(), Nan::GetFunction(Nan::New(getScreenSize)).ToLocalChecked()); - + Nan::Set(target, Nan::New("captureScreen").ToLocalChecked(), Nan::GetFunction(Nan::New(captureScreen)).ToLocalChecked()); - + Nan::Set(target, Nan::New("getColor").ToLocalChecked(), Nan::GetFunction(Nan::New(getColor)).ToLocalChecked()); } From 7720012fde08c33c1e2dfc80abac42026222dc47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Siggi=20D=C3=BCnkel?= Date: Fri, 29 Apr 2016 23:04:38 +0200 Subject: [PATCH 2/4] fix spacing --- src/robotjs.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/robotjs.cc b/src/robotjs.cc index e967f829..688c3b11 100644 --- a/src/robotjs.cc +++ b/src/robotjs.cc @@ -323,7 +323,7 @@ static KeyNames key_names[] = { "shift", K_SHIFT }, { "space", K_SPACE }, { "printscreen", K_PRINTSCREEN }, - { "insert", K_INSERT }, + { "insert", K_INSERT }, { "audio_mute", K_AUDIO_VOLUME_MUTE }, { "audio_vol_down", K_AUDIO_VOLUME_DOWN }, From 3ce729f5fcbb85b1edde31c45cb575e3279ee86f Mon Sep 17 00:00:00 2001 From: Siggi Duenkel Date: Fri, 29 Apr 2016 23:39:35 +0200 Subject: [PATCH 3/4] fixing insert-key for x11 --- src/keycode.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/keycode.h b/src/keycode.h index 4ae773d7..15983cb2 100644 --- a/src/keycode.h +++ b/src/keycode.h @@ -111,6 +111,7 @@ enum _MMKeyCode { K_SHIFT = XK_Shift_L, K_CAPSLOCK = XK_Shift_Lock, K_SPACE = XK_space, + K_INSERT = XK_Insert, K_PRINTSCREEN = XK_Print, K_AUDIO_VOLUME_MUTE = XF86XK_AudioMute, From 037abf3c12636f8e37e8ba17ee99aed29fd46c73 Mon Sep 17 00:00:00 2001 From: Siggi Duenkel Date: Sun, 1 May 2016 13:26:37 +0200 Subject: [PATCH 4/4] fixing whitespaces caused by editor-settings --- src/keycode.h | 4 +-- src/robotjs.cc | 86 +++++++++++++++++++++++++------------------------- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/keycode.h b/src/keycode.h index 15983cb2..cb3b8bb3 100644 --- a/src/keycode.h +++ b/src/keycode.h @@ -5,7 +5,7 @@ #include "os.h" #ifdef __cplusplus -extern "C" +extern "C" { #endif @@ -14,7 +14,7 @@ extern "C" #include /* Really only need */ #include #import - + enum _MMKeyCode { K_NOT_A_KEY = 9999, K_BACKSPACE = kVK_Delete, diff --git a/src/robotjs.cc b/src/robotjs.cc index 688c3b11..9f9c2dea 100644 --- a/src/robotjs.cc +++ b/src/robotjs.cc @@ -18,8 +18,8 @@ int mouseDelay = 10; int keyboardDelay = 10; /* - __ __ -| \/ | ___ _ _ ___ ___ + __ __ +| \/ | ___ _ _ ___ ___ | |\/| |/ _ \| | | / __|/ _ \ | | | | (_) | |_| \__ \ __/ |_| |_|\___/ \__,_|___/\___| @@ -238,21 +238,21 @@ NAN_METHOD(setMouseDelay) info.GetReturnValue().Set(Nan::New(1)); } -NAN_METHOD(scrollMouse) +NAN_METHOD(scrollMouse) { Nan::HandleScope scope; //Get the values of magnitude and direction from the arguments list. - if(info.Length() == 2) + if(info.Length() == 2) { int scrollMagnitude = info[0]->Int32Value(); char *s; Nan::Utf8String sstr(info[1]); s = *sstr; - + MMMouseWheelDirection scrollDirection; - + if (strcmp(s, "up") == 0) { scrollDirection = DIRECTION_UP; @@ -265,26 +265,26 @@ NAN_METHOD(scrollMouse) { return Nan::ThrowError("Invalid scroll direction specified."); } - + scrollMouse(scrollMagnitude, scrollDirection); microsleep(mouseDelay); - + info.GetReturnValue().Set(Nan::New(1)); - } - else + } + else { return Nan::ThrowError("Invalid number of arguments."); } } /* - _ __ _ _ + _ __ _ _ | |/ /___ _ _| |__ ___ __ _ _ __ __| | | ' // _ \ | | | '_ \ / _ \ / _` | '__/ _` | | . \ __/ |_| | |_) | (_) | (_| | | | (_| | |_|\_\___|\__, |_.__/ \___/ \__,_|_| \__,_| - |___/ + |___/ */ -struct KeyNames +struct KeyNames { const char* name; MMKeyCode key; @@ -324,7 +324,7 @@ static KeyNames key_names[] = { "space", K_SPACE }, { "printscreen", K_PRINTSCREEN }, { "insert", K_INSERT }, - + { "audio_mute", K_AUDIO_VOLUME_MUTE }, { "audio_vol_down", K_AUDIO_VOLUME_DOWN }, { "audio_vol_up", K_AUDIO_VOLUME_UP }, @@ -337,7 +337,7 @@ static KeyNames key_names[] = { "audio_forward", K_AUDIO_FORWARD }, { "audio_repeat", K_AUDIO_REPEAT }, { "audio_random", K_AUDIO_RANDOM }, - + { "lights_mon_up", K_LIGHTS_MON_UP }, { "lights_mon_down", K_LIGHTS_MON_DOWN }, { "lights_kbd_toggle",K_LIGHTS_KBD_TOGGLE }, @@ -360,7 +360,7 @@ int CheckKeyCodes(char* k, MMKeyCode *key) *key = K_NOT_A_KEY; KeyNames* kn = key_names; - while (kn->name) + while (kn->name) { if (strcmp(k, kn->name) == 0) { @@ -370,7 +370,7 @@ int CheckKeyCodes(char* k, MMKeyCode *key) kn++; } - if (*key == K_NOT_A_KEY) + if (*key == K_NOT_A_KEY) { return -2; } @@ -578,9 +578,9 @@ NAN_METHOD(typeStringDelayed) { char *str; Nan::Utf8String string(info[0]); - + str = *string; - + size_t cpm = info[1]->Int32Value(); typeStringDelayed(str, cpm); @@ -601,12 +601,12 @@ NAN_METHOD(setKeyboardDelay) } /* - ____ - / ___| ___ _ __ ___ ___ _ __ - \___ \ / __| '__/ _ \/ _ \ '_ \ + ____ + / ___| ___ _ __ ___ ___ _ __ + \___ \ / __| '__/ _ \/ _ \ '_ \ ___) | (__| | | __/ __/ | | | |____/ \___|_| \___|\___|_| |_| - + */ /** @@ -627,7 +627,7 @@ NAN_METHOD(getPixelColor) { return Nan::ThrowError("Invalid number of arguments."); } - + MMBitmapRef bitmap; MMRGBHex color; @@ -642,9 +642,9 @@ NAN_METHOD(getPixelColor) bitmap = copyMMBitmapFromDisplayInRect(MMRectMake(x, y, 1, 1)); color = MMRGBHexAtPoint(bitmap, 0, 0); - + char hex[7]; - + padHex(color, hex); destroyMMBitmap(bitmap); @@ -666,18 +666,18 @@ NAN_METHOD(getScreenSize) info.GetReturnValue().Set(obj); } -NAN_METHOD(captureScreen) +NAN_METHOD(captureScreen) { size_t x; size_t y; size_t w; size_t h; - - //If user has provided screen coords, use them! + + //If user has provided screen coords, use them! if (info.Length() == 4) { //TODO: Make sure requested coords are within the screen bounds, or we get a seg fault. - // An error message is much nicer! + // An error message is much nicer! x = info[0]->Int32Value(); y = info[1]->Int32Value(); @@ -689,15 +689,15 @@ NAN_METHOD(captureScreen) //We're getting the full screen. x = 0; y = 0; - + //Get screen size. MMSize displaySize = getMainDisplaySize(); w = displaySize.width; h = displaySize.height; } - + MMBitmapRef bitmap = copyMMBitmapFromDisplayInRect(MMRectMake(x, y, w, h)); - + uint32_t bufferSize = bitmap->bytewidth * bitmap->height; Local buffer = Nan::NewBuffer((char*)bitmap->imageBuffer, bufferSize, destroyMMBitmapBuffer, NULL).ToLocalChecked(); @@ -708,17 +708,17 @@ NAN_METHOD(captureScreen) Nan::Set(obj, Nan::New("bitsPerPixel").ToLocalChecked(), Nan::New(bitmap->bitsPerPixel)); Nan::Set(obj, Nan::New("bytesPerPixel").ToLocalChecked(), Nan::New(bitmap->bytesPerPixel)); Nan::Set(obj, Nan::New("image").ToLocalChecked(), buffer); - + info.GetReturnValue().Set(obj); } /* - ____ _ _ -| __ )(_) |_ _ __ ___ __ _ _ __ -| _ \| | __| '_ ` _ \ / _` | '_ \ + ____ _ _ +| __ )(_) |_ _ __ ___ __ _ _ __ +| _ \| | __| '_ ` _ \ / _` | '_ \ | |_) | | |_| | | | | | (_| | |_) | -|____/|_|\__|_| |_| |_|\__,_| .__/ - |_| +|____/|_|\__|_| |_| |_|\__,_| .__/ + |_| */ class BMP @@ -733,7 +733,7 @@ class BMP }; //Convert object from Javascript to a C++ class (BMP). -BMP buildBMP(Local info) +BMP buildBMP(Local info) { Local obj = Nan::To(info).ToLocalChecked(); @@ -805,7 +805,7 @@ NAN_MODULE_INIT(InitAll) Nan::Set(target, Nan::New("mouseToggle").ToLocalChecked(), Nan::GetFunction(Nan::New(mouseToggle)).ToLocalChecked()); - + Nan::Set(target, Nan::New("scrollMouse").ToLocalChecked(), Nan::GetFunction(Nan::New(scrollMouse)).ToLocalChecked()); @@ -832,10 +832,10 @@ NAN_MODULE_INIT(InitAll) Nan::Set(target, Nan::New("getScreenSize").ToLocalChecked(), Nan::GetFunction(Nan::New(getScreenSize)).ToLocalChecked()); - + Nan::Set(target, Nan::New("captureScreen").ToLocalChecked(), Nan::GetFunction(Nan::New(captureScreen)).ToLocalChecked()); - + Nan::Set(target, Nan::New("getColor").ToLocalChecked(), Nan::GetFunction(Nan::New(getColor)).ToLocalChecked()); }