Skip to content

Commit 99a96e0

Browse files
author
verth
committed
fix scroll mouse on windows XP, see #97, C89 (2008) variable declaration on top of function
1 parent 4941c1c commit 99a96e0

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/mouse.c

+20-13
Original file line numberDiff line numberDiff line change
@@ -195,58 +195,65 @@ void doubleClick(MMMouseButton button)
195195
* This uses the magnitude to scroll the required amount in the direction.
196196
* TODO Requires further fine tuning based on the requirements.
197197
*/
198-
void scrollMouse(int scrollMagnitude, MMMouseWheelDirection scrollDirection)
198+
void scrollMouse(int scrollMagnitude, MMMouseWheelDirection scrollDirection)
199199
{
200+
#if defined(IS_WINDOWS)
201+
// Fix for #97 https://github.com/octalmage/robotjs/issues/97,
202+
// C89 needs variables declared on top of functions (mouseScrollInput)
203+
INPUT mouseScrollInput;
204+
#endif
205+
200206
/* Direction should only be considered based on the scrollDirection. This
201207
* Should not interfere. */
202208
int cleanScrollMagnitude = abs(scrollMagnitude);
203209
if (!(scrollDirection == DIRECTION_UP || scrollDirection == DIRECTION_DOWN))
204210
{
205211
return;
206212
}
207-
213+
208214
/* Set up the OS specific solution */
209215
#if defined(__APPLE__)
210-
216+
211217
CGWheelCount wheel = 1;
212218
CGEventRef event;
213-
219+
214220
/* Make scroll magnitude negative if we're scrolling down. */
215221
cleanScrollMagnitude = cleanScrollMagnitude * scrollDirection;
216-
222+
217223
event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitLine, wheel, cleanScrollMagnitude, 0);
218224
CGEventPost(kCGHIDEventTap, event);
219-
225+
220226
#elif defined(USE_X11)
221227

222228
int x;
223229
int dir = 4; /* Button 4 is up, 5 is down. */
224230
Display *display = XGetMainDisplay();
225-
231+
226232
if (scrollDirection == DIRECTION_DOWN)
227233
{
228234
dir = 5;
229235
}
230-
236+
231237
for (x = 0; x < cleanScrollMagnitude; x++)
232238
{
233239
XTestFakeButtonEvent(display, dir, 1, CurrentTime);
234240
XTestFakeButtonEvent(display, dir, 0, CurrentTime);
235241
}
236-
242+
237243
XFlush(display);
238-
244+
239245
#elif defined(IS_WINDOWS)
240-
//FIXME: Need to figure out why this code doesn't work on Windows XP.
241-
/*INPUT mouseScrollInput;
246+
242247
mouseScrollInput.type = INPUT_MOUSE;
243248
mouseScrollInput.mi.dx = 0;
244249
mouseScrollInput.mi.dy = 0;
245250
mouseScrollInput.mi.dwFlags = MOUSEEVENTF_WHEEL;
246251
mouseScrollInput.mi.time = 0;
247252
mouseScrollInput.mi.dwExtraInfo = 0;
248253
mouseScrollInput.mi.mouseData = WHEEL_DELTA * scrollDirection * cleanScrollMagnitude;
249-
SendInput(1, &mouseScrollInput, sizeof(mouseScrollInput));*/
254+
255+
SendInput(1, &mouseScrollInput, sizeof(mouseScrollInput));
256+
250257
#endif
251258
}
252259

0 commit comments

Comments
 (0)