-
Notifications
You must be signed in to change notification settings - Fork 978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changed mouseScroll to use X and Y as direction. #194
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9917f49
Changed mouseScroll to use X and Y as direction.
BHamrick1 51082e9
Fixed scroll now using signed ints.
BHamrick1 60021fc
Fixed unused variable warning.
BHamrick1 b6eecbf
Fixed old variable left over.
BHamrick1 3f3c5c5
Fixed error: ‘for’ loop initial declarations are only allowed in C99 …
BHamrick1 9623852
Fixed formatting
BHamrick1 e16b821
Merge branch 'master' of https://github.com/octalmage/robotjs
BHamrick1 0fef6e8
Merge branch 'master' of https://github.com/octalmage/robotjs
BHamrick1 630b198
Fixed spacing
BHamrick1 3ff4434
Fixed spacing.
BHamrick1 6f8d2b6
Accidentally added old scroll code back.
BHamrick1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,71 +232,75 @@ 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(int x, int y) | ||
{ | ||
#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, y, 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 (y < 0){ | ||
ydir = 5; | ||
} | ||
|
||
for (x = 0; x < cleanScrollMagnitude; x++) | ||
{ | ||
XTestFakeButtonEvent(display, dir, 1, CurrentTime); | ||
XTestFakeButtonEvent(display, dir, 0, CurrentTime); | ||
if (x < 0){ | ||
xdir = 7; | ||
} | ||
|
||
int xi; | ||
int yi; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind fixing the whitespace here? |
||
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) | ||
|
||
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)); | ||
#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 * 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 | ||
} | ||
|
||
/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,41 +240,17 @@ 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spaces here too! |
||
{ | ||
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)); | ||
} | ||
/* | ||
_ __ _ _ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spaces -> tabs.