Skip to content
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

fix for #97, mouseScroll Windows XP #163

Merged
merged 1 commit into from Feb 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions src/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,58 +195,65 @@ void doubleClick(MMMouseButton button)
* 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 scrollMagnitude, MMMouseWheelDirection scrollDirection)
{
#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;
}

/* Set up the OS specific solution */
#if defined(__APPLE__)

CGWheelCount wheel = 1;
CGEventRef event;

/* Make scroll magnitude negative if we're scrolling down. */
cleanScrollMagnitude = cleanScrollMagnitude * scrollDirection;

event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitLine, wheel, cleanScrollMagnitude, 0);
CGEventPost(kCGHIDEventTap, event);

#elif defined(USE_X11)

int x;
int dir = 4; /* Button 4 is up, 5 is down. */
Display *display = XGetMainDisplay();

if (scrollDirection == DIRECTION_DOWN)
{
dir = 5;
}

for (x = 0; x < cleanScrollMagnitude; x++)
{
XTestFakeButtonEvent(display, dir, 1, CurrentTime);
XTestFakeButtonEvent(display, dir, 0, CurrentTime);
}

XFlush(display);

#elif defined(IS_WINDOWS)
//FIXME: Need to figure out why this code doesn't work on Windows XP.
/*INPUT mouseScrollInput;

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));*/

SendInput(1, &mouseScrollInput, sizeof(mouseScrollInput));

#endif
}

Expand Down