Skip to content

Commit

Permalink
Windows scrolling bug
Browse files Browse the repository at this point in the history
Closes #360
  • Loading branch information
MariaDima committed Jan 4, 2018
1 parent d021733 commit b4869dd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
28 changes: 20 additions & 8 deletions src/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,20 @@ void scrollMouse(int x, int y)

#elif defined(USE_X11)

int ydir = 4; /* Button 4 is up, 5 is down. */
int xdir = 6;
/*
X11 Mouse Button Numbering
1 = left button
2 = middle button (pressing the scroll wheel)
3 = right button
4 = turn scroll wheel up
5 = turn scroll wheel down
6 = push scroll wheel left
7 = push scroll wheel right
8 = 4th button (aka browser backward button)
9 = 5th button (aka browser forward button)
*/
int ydir = 4; // Button 4 is up, 5 is down.
int xdir = 6; // Button 6 is left, 7 is right.
Display *display = XGetMainDisplay();

if (y < 0){
Expand All @@ -274,8 +286,8 @@ void scrollMouse(int x, int y)
XTestFakeButtonEvent(display, xdir, 0, CurrentTime);
}
for (yi = 0; yi < abs(y); yi++) {
YTestFakeButtonEvent(display, ydir, 1, CurrentTime);
YTestFakeButtonEvent(display, ydir, 0, CurrentTime);
XTestFakeButtonEvent(display, ydir, 1, CurrentTime);
XTestFakeButtonEvent(display, ydir, 0, CurrentTime);
}

XFlush(display);
Expand All @@ -285,18 +297,18 @@ void scrollMouse(int x, int y)
mouseScrollInputH.type = INPUT_MOUSE;
mouseScrollInputH.mi.dx = 0;
mouseScrollInputH.mi.dy = 0;
mouseScrollInputH.mi.dwFlags = MOUSEEVENTF_WHEEL;
mouseScrollInputH.mi.dwFlags = MOUSEEVENTF_HWHEEL;
mouseScrollInputH.mi.time = 0;
mouseScrollInputH.mi.dwExtraInfo = 0;
mouseScrollInputH.mi.mouseData = WHEEL_DELTA * x;
mouseScrollInputH.mi.mouseData = x;

mouseScrollInputV.type = INPUT_MOUSE;
mouseScrollInputV.mi.dx = 0;
mouseScrollInputV.mi.dy = 0;
mouseScrollInputV.mi.dwFlags = MOUSEEVENTF_HWHEEL;
mouseScrollInputV.mi.dwFlags = MOUSEEVENTF_WHEEL;
mouseScrollInputV.mi.time = 0;
mouseScrollInputV.mi.dwExtraInfo = 0;
mouseScrollInputV.mi.mouseData = WHEEL_DELTA * y;
mouseScrollInputV.mi.mouseData = y;

SendInput(1, &mouseScrollInputH, sizeof(mouseScrollInputH));
SendInput(1, &mouseScrollInputV, sizeof(mouseScrollInputV));
Expand Down
20 changes: 19 additions & 1 deletion test/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,23 @@ test('Drag the mouse.', function(t)

});

//TODO: Need tests for mouseToggle, and scrollMouse.
test('Mouse scroll.', function(t)
{
t.plan(9);
t.ok(lastKnownPos = robot.getMousePos(), 'successfully retrieved mouse position.');
t.ok(robot.mouseClick() === 1, 'click the mouse (no button specified).');
t.ok(robot.scrollMouse(0, 1 * 120) === 1, '1 scroll up.');
t.ok(robot.scrollMouse(0, 20 * 120) === 1, '20 scrolls up.');
t.ok(robot.scrollMouse(0, -5 * 120) === 1, '5 scrolls down.');
t.ok(robot.scrollMouse(1 * 120, 0) === 1, '1 scroll right.');
t.ok(robot.scrollMouse(20 * 120, 0) === 1, '20 scrolls right.');
t.ok(robot.scrollMouse(-5 * 120, 0) === 1, '5 scrolls left.');
t.ok(robot.scrollMouse(-5 * 120, -5 * 120) === 1, '5 scrolls left.');
});

test('Mouse Toggle', function(t)
{
t.plan(2);
t.ok(lastKnownPos = robot.getMousePos(), 'successfully retrieved mouse position.');
t.ok(robot.mouseToggle('up', 'right') === 1, 'right click was pressed.');
});

0 comments on commit b4869dd

Please sign in to comment.