From 9917f490c30e8eeb3f7f8e40bf5e7a4f21644c88 Mon Sep 17 00:00:00 2001 From: Ben Hamrick Date: Wed, 18 May 2016 14:29:23 -0400 Subject: [PATCH 1/9] Changed mouseScroll to use X and Y as direction. --- src/mouse.c | 95 ++++++++++++++++++++++++++------------------------ src/mouse.h | 2 +- src/robotjs.cc | 48 +++++++------------------ 3 files changed, 63 insertions(+), 82 deletions(-) diff --git a/src/mouse.c b/src/mouse.c index 7d8bde30..e3828d63 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -232,71 +232,74 @@ void doubleClick(MMMouseButton button) #endif } -/** - * Function used to scroll the screen in the required direction. - * This uses the magnitude to scroll the required amount in the direction. - * TODO Requires further fine tuning based on the requirements. - */ -void scrollMouse(int scrollMagnitude, MMMouseWheelDirection scrollDirection) +void scrollMouse(MMPoint scroll) { - #if defined(IS_WINDOWS) +#if defined(IS_WINDOWS) // Fix for #97 https://github.com/octalmage/robotjs/issues/97, // 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; - } + INPUT mouseScrollInputH; + INPUT mouseScrollInputV; +#endif - /* Set up the OS specific solution */ - #if defined(__APPLE__) + /* Direction should only be considered based on the scrollDirection. This + * Should not interfere. */ - CGWheelCount wheel = 1; - CGEventRef event; + /* Set up the OS specific solution */ +#if defined(__APPLE__) - /* Make scroll magnitude negative if we're scrolling down. */ - cleanScrollMagnitude = cleanScrollMagnitude * scrollDirection; + CGEventRef event; - event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitLine, wheel, cleanScrollMagnitude, 0); + event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 2, scroll.y, scroll.x); CGEventPost(kCGHIDEventTap, event); - #elif defined(USE_X11) + CFRelease(event); + +#elif defined(USE_X11) - int x; - int dir = 4; /* Button 4 is up, 5 is down. */ + int ydir = 4; /* Button 4 is up, 5 is down. */ + int xdir = 6; Display *display = XGetMainDisplay(); - if (scrollDirection == DIRECTION_DOWN) - { - dir = 5; + if (scroll.y < 0){ + ydir = 5; } - - for (x = 0; x < cleanScrollMagnitude; x++) - { - XTestFakeButtonEvent(display, dir, 1, CurrentTime); - XTestFakeButtonEvent(display, dir, 0, CurrentTime); + if (scroll.x < 0){ + xdir = 7; } - XFlush(display); + for (int x = 0; x < abs(scroll.x); x++) { + XTestFakeButtonEvent(display, xdir, 1, CurrentTime); + XTestFakeButtonEvent(display, xdir, 0, CurrentTime); + } - #elif defined(IS_WINDOWS) + for (int y = 0; y < abs(scroll.y); y++) { + XTestFakeButtonEvent(display, ydir, 1, CurrentTime); + XTestFakeButtonEvent(display, ydir, 0, CurrentTime); + } - 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; + XFlush(display); - SendInput(1, &mouseScrollInput, sizeof(mouseScrollInput)); +#elif defined(IS_WINDOWS) - #endif + mouseScrollInputH.type = INPUT_MOUSE; + mouseScrollInputH.mi.dx = 0; + mouseScrollInputH.mi.dy = 0; + mouseScrollInputH.mi.dwFlags = MOUSEEVENTF_WHEEL; + mouseScrollInputH.mi.time = 0; + mouseScrollInputH.mi.dwExtraInfo = 0; + mouseScrollInputH.mi.mouseData = WHEEL_DELTA * scroll.x; + + mouseScrollInputV.type = INPUT_MOUSE; + mouseScrollInputV.mi.dx = 0; + mouseScrollInputV.mi.dy = 0; + mouseScrollInputV.mi.dwFlags = MOUSEEVENTF_HWHEEL; + mouseScrollInputV.mi.time = 0; + mouseScrollInputV.mi.dwExtraInfo = 0; + mouseScrollInputV.mi.mouseData = WHEEL_DELTA * scroll.y; + + SendInput(1, &mouseScrollInputH, sizeof(mouseScrollInputH)); + SendInput(1, &mouseScrollInputV, sizeof(mouseScrollInputV)); +#endif } /* diff --git a/src/mouse.h b/src/mouse.h index 37be3e6c..481873df 100644 --- a/src/mouse.h +++ b/src/mouse.h @@ -90,7 +90,7 @@ void doubleClick(MMMouseButton button); /* Scrolls the mouse in the stated direction. * TODO: Add a smoothly scroll mouse next. */ -void scrollMouse(int scrollMagnitude, MMMouseWheelDirection scrollDirection); +void scrollMouse(MMPoint scroll); #endif /* MOUSE_H */ diff --git a/src/robotjs.cc b/src/robotjs.cc index 9f9c2dea..fd3231bd 100644 --- a/src/robotjs.cc +++ b/src/robotjs.cc @@ -240,41 +240,19 @@ NAN_METHOD(setMouseDelay) NAN_METHOD(scrollMouse) { - Nan::HandleScope scope; - - //Get the values of magnitude and direction from the arguments list. - 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; - } - else if (strcmp(s, "down") == 0) - { - scrollDirection = DIRECTION_DOWN; - } - else - { - return Nan::ThrowError("Invalid scroll direction specified."); - } - - scrollMouse(scrollMagnitude, scrollDirection); - microsleep(mouseDelay); - - info.GetReturnValue().Set(Nan::New(1)); - } - else - { - return Nan::ThrowError("Invalid number of arguments."); - } + if (info.Length() != 2) + { + return Nan::ThrowError("Invalid number of arguments."); + } + size_t x = info[0]->Int32Value(); + size_t y = info[1]->Int32Value(); + + MMPoint point; + point = MMPointMake(x, y); + scrollMouse(point); + microsleep(mouseDelay); + + info.GetReturnValue().Set(Nan::New(1)); } /* _ __ _ _ From 51082e9e0efad285b3d2d72d3acc3624355489f2 Mon Sep 17 00:00:00 2001 From: Ben Hamrick Date: Wed, 18 May 2016 16:03:59 -0400 Subject: [PATCH 2/9] Fixed scroll now using signed ints. --- src/mouse.c | 12 ++++++------ src/mouse.h | 2 +- src/robotjs.cc | 7 +++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/mouse.c b/src/mouse.c index e3828d63..67d2a559 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -232,7 +232,7 @@ void doubleClick(MMMouseButton button) #endif } -void scrollMouse(MMPoint scroll) +void scrollMouse(int x, int y) { #if defined(IS_WINDOWS) // Fix for #97 https://github.com/octalmage/robotjs/issues/97, @@ -249,7 +249,7 @@ void scrollMouse(MMPoint scroll) CGEventRef event; - event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 2, scroll.y, scroll.x); + event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 2, y, x); CGEventPost(kCGHIDEventTap, event); CFRelease(event); @@ -260,10 +260,10 @@ void scrollMouse(MMPoint scroll) int xdir = 6; Display *display = XGetMainDisplay(); - if (scroll.y < 0){ + if (y < 0){ ydir = 5; } - if (scroll.x < 0){ + if (x < 0){ xdir = 7; } @@ -287,7 +287,7 @@ void scrollMouse(MMPoint scroll) mouseScrollInputH.mi.dwFlags = MOUSEEVENTF_WHEEL; mouseScrollInputH.mi.time = 0; mouseScrollInputH.mi.dwExtraInfo = 0; - mouseScrollInputH.mi.mouseData = WHEEL_DELTA * scroll.x; + mouseScrollInputH.mi.mouseData = WHEEL_DELTA * x; mouseScrollInputV.type = INPUT_MOUSE; mouseScrollInputV.mi.dx = 0; @@ -295,7 +295,7 @@ void scrollMouse(MMPoint scroll) mouseScrollInputV.mi.dwFlags = MOUSEEVENTF_HWHEEL; mouseScrollInputV.mi.time = 0; mouseScrollInputV.mi.dwExtraInfo = 0; - mouseScrollInputV.mi.mouseData = WHEEL_DELTA * scroll.y; + mouseScrollInputV.mi.mouseData = WHEEL_DELTA * y; SendInput(1, &mouseScrollInputH, sizeof(mouseScrollInputH)); SendInput(1, &mouseScrollInputV, sizeof(mouseScrollInputV)); diff --git a/src/mouse.h b/src/mouse.h index 481873df..643a3a98 100644 --- a/src/mouse.h +++ b/src/mouse.h @@ -90,7 +90,7 @@ void doubleClick(MMMouseButton button); /* Scrolls the mouse in the stated direction. * TODO: Add a smoothly scroll mouse next. */ -void scrollMouse(MMPoint scroll); +void scrollMouse(int x, int y); #endif /* MOUSE_H */ diff --git a/src/robotjs.cc b/src/robotjs.cc index fd3231bd..6fe9159b 100644 --- a/src/robotjs.cc +++ b/src/robotjs.cc @@ -244,12 +244,11 @@ NAN_METHOD(scrollMouse) { return Nan::ThrowError("Invalid number of arguments."); } - size_t x = info[0]->Int32Value(); - size_t y = info[1]->Int32Value(); + int x = info[0]->Int32Value(); + int y = info[1]->Int32Value(); MMPoint point; - point = MMPointMake(x, y); - scrollMouse(point); + scrollMouse(x, y); microsleep(mouseDelay); info.GetReturnValue().Set(Nan::New(1)); From 60021fc9fb1042ab526258859dfe6cc06887b8bb Mon Sep 17 00:00:00 2001 From: Ben Hamrick Date: Wed, 18 May 2016 16:28:12 -0400 Subject: [PATCH 3/9] Fixed unused variable warning. --- src/robotjs.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/robotjs.cc b/src/robotjs.cc index 6fe9159b..18d5f6ad 100644 --- a/src/robotjs.cc +++ b/src/robotjs.cc @@ -247,7 +247,6 @@ NAN_METHOD(scrollMouse) int x = info[0]->Int32Value(); int y = info[1]->Int32Value(); - MMPoint point; scrollMouse(x, y); microsleep(mouseDelay); From b6eecbf6364bf92dd8a6329eda0725444bcf2920 Mon Sep 17 00:00:00 2001 From: Ben Hamrick Date: Wed, 18 May 2016 16:39:20 -0400 Subject: [PATCH 4/9] Fixed old variable left over. Fixed variable overlaping. --- src/mouse.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mouse.c b/src/mouse.c index 67d2a559..dd1c2423 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -267,14 +267,14 @@ void scrollMouse(int x, int y) xdir = 7; } - for (int x = 0; x < abs(scroll.x); x++) { + for (int xi = 0; xi < abs(x); xi++) { XTestFakeButtonEvent(display, xdir, 1, CurrentTime); XTestFakeButtonEvent(display, xdir, 0, CurrentTime); } - for (int y = 0; y < abs(scroll.y); y++) { - XTestFakeButtonEvent(display, ydir, 1, CurrentTime); - XTestFakeButtonEvent(display, ydir, 0, CurrentTime); + for (int yi = 0; yi < abs(y); yi++) { + YTestFakeButtonEvent(display, ydir, 1, CurrentTime); + YTestFakeButtonEvent(display, ydir, 0, CurrentTime); } XFlush(display); From 3f3c5c56938b1ba6d148780acb15c9822917e139 Mon Sep 17 00:00:00 2001 From: Ben Hamrick Date: Thu, 19 May 2016 10:11:27 -0400 Subject: [PATCH 5/9] =?UTF-8?q?Fixed=20error:=20=E2=80=98for=E2=80=99=20lo?= =?UTF-8?q?op=20initial=20declarations=20are=20only=20allowed=20in=20C99?= =?UTF-8?q?=20mode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mouse.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/mouse.c b/src/mouse.c index dd1c2423..b437d0be 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -266,13 +266,14 @@ void scrollMouse(int x, int y) if (x < 0){ xdir = 7; } - - for (int xi = 0; xi < abs(x); xi++) { + + int xi; + int yi; + for (xi = 0; xi < abs(x); xi++) { XTestFakeButtonEvent(display, xdir, 1, CurrentTime); XTestFakeButtonEvent(display, xdir, 0, CurrentTime); } - - for (int yi = 0; yi < abs(y); yi++) { + for (yi = 0; yi < abs(y); yi++) { YTestFakeButtonEvent(display, ydir, 1, CurrentTime); YTestFakeButtonEvent(display, ydir, 0, CurrentTime); } From 9623852de02c1d6be52542ebe9b9c05b5f23d883 Mon Sep 17 00:00:00 2001 From: Ben Hamrick Date: Mon, 6 Jun 2016 15:13:07 -0400 Subject: [PATCH 6/9] Fixed formatting --- src/mouse.c | 118 ++++++++++++++++++++++++------------------------- src/robotjs.cc | 92 +++++++++++++++++++------------------- 2 files changed, 105 insertions(+), 105 deletions(-) diff --git a/src/mouse.c b/src/mouse.c index b437d0be..704138e2 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -118,7 +118,7 @@ void moveMouse(MMPoint point) mouseInput.mi.dwExtraInfo = 0; mouseInput.mi.mouseData = 0; SendInput(1, &mouseInput, sizeof(mouseInput)); - + #endif } @@ -202,7 +202,7 @@ void clickMouse(MMMouseButton button) */ void doubleClick(MMMouseButton button) { - + #if defined(IS_MACOSX) /* Double click for Mac. */ @@ -210,17 +210,17 @@ void doubleClick(MMMouseButton button) const CGEventType mouseTypeDown = MMMouseToCGEventType(true, button); const CGEventType mouseTypeUP = MMMouseToCGEventType(false, button); - CGEventRef event = CGEventCreateMouseEvent(NULL, mouseTypeDown, currentPos, kCGMouseButtonLeft); - - /* Set event to double click. */ + CGEventRef event = CGEventCreateMouseEvent(NULL, mouseTypeDown, currentPos, kCGMouseButtonLeft); + + /* Set event to double click. */ CGEventSetIntegerValueField(event, kCGMouseEventClickState, 2); - - CGEventPost(kCGHIDEventTap, event); - - CGEventSetType(event, mouseTypeUP); - CGEventPost(kCGHIDEventTap, event); - CFRelease(event); + CGEventPost(kCGHIDEventTap, event); + + CGEventSetType(event, mouseTypeUP); + CGEventPost(kCGHIDEventTap, event); + + CFRelease(event); #else @@ -228,17 +228,17 @@ void doubleClick(MMMouseButton button) clickMouse(button); microsleep(200); clickMouse(button); - + #endif } void scrollMouse(int x, int y) { #if defined(IS_WINDOWS) - // Fix for #97 https://github.com/octalmage/robotjs/issues/97, - // C89 needs variables declared on top of functions (mouseScrollInput) - INPUT mouseScrollInputH; - INPUT mouseScrollInputV; + // Fix for #97 https://github.com/octalmage/robotjs/issues/97, + // C89 needs variables declared on top of functions (mouseScrollInput) + INPUT mouseScrollInputH; + INPUT mouseScrollInputV; #endif /* Direction should only be considered based on the scrollDirection. This @@ -247,59 +247,59 @@ void scrollMouse(int x, int y) /* Set up the OS specific solution */ #if defined(__APPLE__) - CGEventRef event; + CGEventRef event; - event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 2, y, x); - CGEventPost(kCGHIDEventTap, event); + event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 2, y, x); + CGEventPost(kCGHIDEventTap, event); - CFRelease(event); + CFRelease(event); #elif defined(USE_X11) - int ydir = 4; /* Button 4 is up, 5 is down. */ - int xdir = 6; - Display *display = XGetMainDisplay(); + int ydir = 4; /* Button 4 is up, 5 is down. */ + int xdir = 6; + Display *display = XGetMainDisplay(); - if (y < 0){ - ydir = 5; - } - if (x < 0){ - xdir = 7; - } - - int xi; - int yi; - for (xi = 0; xi < abs(x); xi++) { - XTestFakeButtonEvent(display, xdir, 1, CurrentTime); - XTestFakeButtonEvent(display, xdir, 0, CurrentTime); - } - for (yi = 0; yi < abs(y); yi++) { - YTestFakeButtonEvent(display, ydir, 1, CurrentTime); - YTestFakeButtonEvent(display, ydir, 0, CurrentTime); - } + if (y < 0){ + ydir = 5; + } + if (x < 0){ + xdir = 7; + } - XFlush(display); + int xi; + int yi; + for (xi = 0; xi < abs(x); xi++) { + XTestFakeButtonEvent(display, xdir, 1, CurrentTime); + XTestFakeButtonEvent(display, xdir, 0, CurrentTime); + } + for (yi = 0; yi < abs(y); yi++) { + YTestFakeButtonEvent(display, ydir, 1, CurrentTime); + YTestFakeButtonEvent(display, ydir, 0, CurrentTime); + } + + XFlush(display); #elif defined(IS_WINDOWS) - mouseScrollInputH.type = INPUT_MOUSE; - mouseScrollInputH.mi.dx = 0; - mouseScrollInputH.mi.dy = 0; - mouseScrollInputH.mi.dwFlags = MOUSEEVENTF_WHEEL; - mouseScrollInputH.mi.time = 0; - mouseScrollInputH.mi.dwExtraInfo = 0; - mouseScrollInputH.mi.mouseData = WHEEL_DELTA * x; - - mouseScrollInputV.type = INPUT_MOUSE; - mouseScrollInputV.mi.dx = 0; - mouseScrollInputV.mi.dy = 0; - mouseScrollInputV.mi.dwFlags = MOUSEEVENTF_HWHEEL; - mouseScrollInputV.mi.time = 0; - mouseScrollInputV.mi.dwExtraInfo = 0; - mouseScrollInputV.mi.mouseData = WHEEL_DELTA * y; - - SendInput(1, &mouseScrollInputH, sizeof(mouseScrollInputH)); - SendInput(1, &mouseScrollInputV, sizeof(mouseScrollInputV)); + mouseScrollInputH.type = INPUT_MOUSE; + mouseScrollInputH.mi.dx = 0; + mouseScrollInputH.mi.dy = 0; + mouseScrollInputH.mi.dwFlags = MOUSEEVENTF_WHEEL; + mouseScrollInputH.mi.time = 0; + mouseScrollInputH.mi.dwExtraInfo = 0; + mouseScrollInputH.mi.mouseData = WHEEL_DELTA * x; + + mouseScrollInputV.type = INPUT_MOUSE; + mouseScrollInputV.mi.dx = 0; + mouseScrollInputV.mi.dy = 0; + mouseScrollInputV.mi.dwFlags = MOUSEEVENTF_HWHEEL; + mouseScrollInputV.mi.time = 0; + mouseScrollInputV.mi.dwExtraInfo = 0; + mouseScrollInputV.mi.mouseData = WHEEL_DELTA * y; + + SendInput(1, &mouseScrollInputH, sizeof(mouseScrollInputH)); + SendInput(1, &mouseScrollInputV, sizeof(mouseScrollInputV)); #endif } diff --git a/src/robotjs.cc b/src/robotjs.cc index 18d5f6ad..2c6bb4af 100644 --- a/src/robotjs.cc +++ b/src/robotjs.cc @@ -18,8 +18,8 @@ int mouseDelay = 10; int keyboardDelay = 10; /* - __ __ -| \/ | ___ _ _ ___ ___ + __ __ +| \/ | ___ _ _ ___ ___ | |\/| |/ _ \| | | / __|/ _ \ | | | | (_) | |_| \__ \ __/ |_| |_|\___/ \__,_|___/\___| @@ -238,29 +238,29 @@ NAN_METHOD(setMouseDelay) info.GetReturnValue().Set(Nan::New(1)); } -NAN_METHOD(scrollMouse) +NAN_METHOD(scrollMouse) { - if (info.Length() != 2) - { - return Nan::ThrowError("Invalid number of arguments."); + if (info.Length() != 2) + { + return Nan::ThrowError("Invalid number of arguments."); } - int x = info[0]->Int32Value(); - int y = info[1]->Int32Value(); - - scrollMouse(x, y); - microsleep(mouseDelay); - - info.GetReturnValue().Set(Nan::New(1)); + int x = info[0]->Int32Value(); + int y = info[1]->Int32Value(); + + scrollMouse(x, y); + microsleep(mouseDelay); + + info.GetReturnValue().Set(Nan::New(1)); } /* - _ __ _ _ + _ __ _ _ | |/ /___ _ _| |__ ___ __ _ _ __ __| | | ' // _ \ | | | '_ \ / _ \ / _` | '__/ _` | | . \ __/ |_| | |_) | (_) | (_| | | | (_| | |_|\_\___|\__, |_.__/ \___/ \__,_|_| \__,_| - |___/ + |___/ */ -struct KeyNames +struct KeyNames { const char* name; MMKeyCode key; @@ -300,7 +300,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 }, @@ -313,7 +313,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 }, @@ -336,7 +336,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) { @@ -346,7 +346,7 @@ int CheckKeyCodes(char* k, MMKeyCode *key) kn++; } - if (*key == K_NOT_A_KEY) + if (*key == K_NOT_A_KEY) { return -2; } @@ -554,9 +554,9 @@ NAN_METHOD(typeStringDelayed) { char *str; Nan::Utf8String string(info[0]); - + str = *string; - + size_t cpm = info[1]->Int32Value(); typeStringDelayed(str, cpm); @@ -577,12 +577,12 @@ NAN_METHOD(setKeyboardDelay) } /* - ____ - / ___| ___ _ __ ___ ___ _ __ - \___ \ / __| '__/ _ \/ _ \ '_ \ + ____ + / ___| ___ _ __ ___ ___ _ __ + \___ \ / __| '__/ _ \/ _ \ '_ \ ___) | (__| | | __/ __/ | | | |____/ \___|_| \___|\___|_| |_| - + */ /** @@ -603,7 +603,7 @@ NAN_METHOD(getPixelColor) { return Nan::ThrowError("Invalid number of arguments."); } - + MMBitmapRef bitmap; MMRGBHex color; @@ -618,9 +618,9 @@ NAN_METHOD(getPixelColor) bitmap = copyMMBitmapFromDisplayInRect(MMRectMake(x, y, 1, 1)); color = MMRGBHexAtPoint(bitmap, 0, 0); - + char hex[7]; - + padHex(color, hex); destroyMMBitmap(bitmap); @@ -642,18 +642,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(); @@ -665,15 +665,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(); @@ -684,17 +684,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 @@ -709,7 +709,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(); @@ -781,7 +781,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()); @@ -808,10 +808,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 630b1981b1b2d3793943e53d7d4c07db734656a3 Mon Sep 17 00:00:00 2001 From: Ben Hamrick Date: Tue, 10 Jan 2017 11:29:27 -0500 Subject: [PATCH 7/9] Fixed spacing --- src/mouse.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mouse.c b/src/mouse.c index 704138e2..af78cdc4 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -252,7 +252,7 @@ void scrollMouse(int x, int y) event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 2, y, x); CGEventPost(kCGHIDEventTap, event); - CFRelease(event); + CFRelease(event); #elif defined(USE_X11) @@ -267,8 +267,8 @@ void scrollMouse(int x, int y) xdir = 7; } - int xi; - int yi; + int xi; + int yi; for (xi = 0; xi < abs(x); xi++) { XTestFakeButtonEvent(display, xdir, 1, CurrentTime); XTestFakeButtonEvent(display, xdir, 0, CurrentTime); From 3ff44342daf30c023140f976cc77fedb649b3730 Mon Sep 17 00:00:00 2001 From: Ben Hamrick Date: Tue, 10 Jan 2017 11:32:33 -0500 Subject: [PATCH 8/9] Fixed spacing. --- src/robotjs.cc | 58 +++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/robotjs.cc b/src/robotjs.cc index 28e05577..859e2180 100644 --- a/src/robotjs.cc +++ b/src/robotjs.cc @@ -244,38 +244,38 @@ NAN_METHOD(setMouseDelay) NAN_METHOD(scrollMouse) { if (info.Length() != 2) - { - return Nan::ThrowError("Invalid number of arguments."); - } + { + return Nan::ThrowError("Invalid number of arguments."); + } Nan::HandleScope scope; //Get the values of magnitude and direction from the arguments list. - int scrollMagnitude = info[0]->Int32Value(); - char *s; - - Nan::Utf8String sstr(info[1]); - s = *sstr; - - MMMouseWheelDirection scrollDirection; - - if (strcmp(s, "up") == 0) - { - scrollDirection = DIRECTION_UP; - } - else if (strcmp(s, "down") == 0) - { - scrollDirection = DIRECTION_DOWN; - } - else - { - return Nan::ThrowError("Invalid scroll direction specified."); - } - - scrollMouse(scrollMagnitude, scrollDirection); - microsleep(mouseDelay); - - info.GetReturnValue().Set(Nan::New(1)); - + int scrollMagnitude = info[0]->Int32Value(); + char *s; + + Nan::Utf8String sstr(info[1]); + s = *sstr; + + MMMouseWheelDirection scrollDirection; + + if (strcmp(s, "up") == 0) + { + scrollDirection = DIRECTION_UP; + } + else if (strcmp(s, "down") == 0) + { + scrollDirection = DIRECTION_DOWN; + } + else + { + return Nan::ThrowError("Invalid scroll direction specified."); + } + + scrollMouse(scrollMagnitude, scrollDirection); + microsleep(mouseDelay); + + info.GetReturnValue().Set(Nan::New(1)); + int x = info[0]->Int32Value(); int y = info[1]->Int32Value(); From 6f8d2b6f86df54b5da28b8bed438caf2ad73adc4 Mon Sep 17 00:00:00 2001 From: Ben Hamrick Date: Tue, 10 Jan 2017 17:54:19 -0500 Subject: [PATCH 9/9] Accidentally added old scroll code back. --- src/robotjs.cc | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/src/robotjs.cc b/src/robotjs.cc index 859e2180..7af9e848 100644 --- a/src/robotjs.cc +++ b/src/robotjs.cc @@ -247,35 +247,7 @@ NAN_METHOD(scrollMouse) { return Nan::ThrowError("Invalid number of arguments."); } - Nan::HandleScope scope; - - //Get the values of magnitude and direction from the arguments list. - int scrollMagnitude = info[0]->Int32Value(); - char *s; - - Nan::Utf8String sstr(info[1]); - s = *sstr; - - MMMouseWheelDirection scrollDirection; - - if (strcmp(s, "up") == 0) - { - scrollDirection = DIRECTION_UP; - } - else if (strcmp(s, "down") == 0) - { - scrollDirection = DIRECTION_DOWN; - } - else - { - return Nan::ThrowError("Invalid scroll direction specified."); - } - - scrollMouse(scrollMagnitude, scrollDirection); - microsleep(mouseDelay); - - info.GetReturnValue().Set(Nan::New(1)); - + int x = info[0]->Int32Value(); int y = info[1]->Int32Value();