Skip to content

Commit

Permalink
fix scroll mouse on windows XP, see octalmage#97, C89 (2008) variable…
Browse files Browse the repository at this point in the history
… declaration on top of function
  • Loading branch information
verth committed Feb 18, 2016
1 parent 4941c1c commit 99a96e0
Showing 1 changed file with 20 additions and 13 deletions.
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

0 comments on commit 99a96e0

Please sign in to comment.