Skip to content

Commit b4869dd

Browse files
committed
Windows scrolling bug
Closes #360
1 parent d021733 commit b4869dd

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

src/mouse.c

+20-8
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,20 @@ void scrollMouse(int x, int y)
256256

257257
#elif defined(USE_X11)
258258

259-
int ydir = 4; /* Button 4 is up, 5 is down. */
260-
int xdir = 6;
259+
/*
260+
X11 Mouse Button Numbering
261+
1 = left button
262+
2 = middle button (pressing the scroll wheel)
263+
3 = right button
264+
4 = turn scroll wheel up
265+
5 = turn scroll wheel down
266+
6 = push scroll wheel left
267+
7 = push scroll wheel right
268+
8 = 4th button (aka browser backward button)
269+
9 = 5th button (aka browser forward button)
270+
*/
271+
int ydir = 4; // Button 4 is up, 5 is down.
272+
int xdir = 6; // Button 6 is left, 7 is right.
261273
Display *display = XGetMainDisplay();
262274

263275
if (y < 0){
@@ -274,8 +286,8 @@ void scrollMouse(int x, int y)
274286
XTestFakeButtonEvent(display, xdir, 0, CurrentTime);
275287
}
276288
for (yi = 0; yi < abs(y); yi++) {
277-
YTestFakeButtonEvent(display, ydir, 1, CurrentTime);
278-
YTestFakeButtonEvent(display, ydir, 0, CurrentTime);
289+
XTestFakeButtonEvent(display, ydir, 1, CurrentTime);
290+
XTestFakeButtonEvent(display, ydir, 0, CurrentTime);
279291
}
280292

281293
XFlush(display);
@@ -285,18 +297,18 @@ void scrollMouse(int x, int y)
285297
mouseScrollInputH.type = INPUT_MOUSE;
286298
mouseScrollInputH.mi.dx = 0;
287299
mouseScrollInputH.mi.dy = 0;
288-
mouseScrollInputH.mi.dwFlags = MOUSEEVENTF_WHEEL;
300+
mouseScrollInputH.mi.dwFlags = MOUSEEVENTF_HWHEEL;
289301
mouseScrollInputH.mi.time = 0;
290302
mouseScrollInputH.mi.dwExtraInfo = 0;
291-
mouseScrollInputH.mi.mouseData = WHEEL_DELTA * x;
303+
mouseScrollInputH.mi.mouseData = x;
292304

293305
mouseScrollInputV.type = INPUT_MOUSE;
294306
mouseScrollInputV.mi.dx = 0;
295307
mouseScrollInputV.mi.dy = 0;
296-
mouseScrollInputV.mi.dwFlags = MOUSEEVENTF_HWHEEL;
308+
mouseScrollInputV.mi.dwFlags = MOUSEEVENTF_WHEEL;
297309
mouseScrollInputV.mi.time = 0;
298310
mouseScrollInputV.mi.dwExtraInfo = 0;
299-
mouseScrollInputV.mi.mouseData = WHEEL_DELTA * y;
311+
mouseScrollInputV.mi.mouseData = y;
300312

301313
SendInput(1, &mouseScrollInputH, sizeof(mouseScrollInputH));
302314
SendInput(1, &mouseScrollInputV, sizeof(mouseScrollInputV));

test/mouse.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,23 @@ test('Drag the mouse.', function(t)
109109

110110
});
111111

112-
//TODO: Need tests for mouseToggle, and scrollMouse.
112+
test('Mouse scroll.', function(t)
113+
{
114+
t.plan(9);
115+
t.ok(lastKnownPos = robot.getMousePos(), 'successfully retrieved mouse position.');
116+
t.ok(robot.mouseClick() === 1, 'click the mouse (no button specified).');
117+
t.ok(robot.scrollMouse(0, 1 * 120) === 1, '1 scroll up.');
118+
t.ok(robot.scrollMouse(0, 20 * 120) === 1, '20 scrolls up.');
119+
t.ok(robot.scrollMouse(0, -5 * 120) === 1, '5 scrolls down.');
120+
t.ok(robot.scrollMouse(1 * 120, 0) === 1, '1 scroll right.');
121+
t.ok(robot.scrollMouse(20 * 120, 0) === 1, '20 scrolls right.');
122+
t.ok(robot.scrollMouse(-5 * 120, 0) === 1, '5 scrolls left.');
123+
t.ok(robot.scrollMouse(-5 * 120, -5 * 120) === 1, '5 scrolls left.');
124+
});
113125

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

0 commit comments

Comments
 (0)