Skip to content

Commit

Permalink
Fixed scroll now using signed ints.
Browse files Browse the repository at this point in the history
  • Loading branch information
BHamrick1 committed May 18, 2016
1 parent 9917f49 commit 51082e9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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;
}

Expand All @@ -287,15 +287,15 @@ 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;
mouseScrollInputV.mi.dy = 0;
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));
Expand Down
2 changes: 1 addition & 1 deletion src/mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
7 changes: 3 additions & 4 deletions src/robotjs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 51082e9

Please sign in to comment.