diff --git a/src/mouse.c b/src/mouse.c index af78cdc4..a358182a 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -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){ @@ -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); @@ -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)); diff --git a/test/mouse.js b/test/mouse.js index af156892..12c72c0f 100644 --- a/test/mouse.js +++ b/test/mouse.js @@ -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.'); +});