@@ -195,58 +195,65 @@ void doubleClick(MMMouseButton button)
195
195
* This uses the magnitude to scroll the required amount in the direction.
196
196
* TODO Requires further fine tuning based on the requirements.
197
197
*/
198
- void scrollMouse (int scrollMagnitude , MMMouseWheelDirection scrollDirection )
198
+ void scrollMouse (int scrollMagnitude , MMMouseWheelDirection scrollDirection )
199
199
{
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
+
200
206
/* Direction should only be considered based on the scrollDirection. This
201
207
* Should not interfere. */
202
208
int cleanScrollMagnitude = abs (scrollMagnitude );
203
209
if (!(scrollDirection == DIRECTION_UP || scrollDirection == DIRECTION_DOWN ))
204
210
{
205
211
return ;
206
212
}
207
-
213
+
208
214
/* Set up the OS specific solution */
209
215
#if defined(__APPLE__ )
210
-
216
+
211
217
CGWheelCount wheel = 1 ;
212
218
CGEventRef event ;
213
-
219
+
214
220
/* Make scroll magnitude negative if we're scrolling down. */
215
221
cleanScrollMagnitude = cleanScrollMagnitude * scrollDirection ;
216
-
222
+
217
223
event = CGEventCreateScrollWheelEvent (NULL , kCGScrollEventUnitLine , wheel , cleanScrollMagnitude , 0 );
218
224
CGEventPost (kCGHIDEventTap , event );
219
-
225
+
220
226
#elif defined(USE_X11 )
221
227
222
228
int x ;
223
229
int dir = 4 ; /* Button 4 is up, 5 is down. */
224
230
Display * display = XGetMainDisplay ();
225
-
231
+
226
232
if (scrollDirection == DIRECTION_DOWN )
227
233
{
228
234
dir = 5 ;
229
235
}
230
-
236
+
231
237
for (x = 0 ; x < cleanScrollMagnitude ; x ++ )
232
238
{
233
239
XTestFakeButtonEvent (display , dir , 1 , CurrentTime );
234
240
XTestFakeButtonEvent (display , dir , 0 , CurrentTime );
235
241
}
236
-
242
+
237
243
XFlush (display );
238
-
244
+
239
245
#elif defined(IS_WINDOWS )
240
- //FIXME: Need to figure out why this code doesn't work on Windows XP.
241
- /*INPUT mouseScrollInput;
246
+
242
247
mouseScrollInput .type = INPUT_MOUSE ;
243
248
mouseScrollInput .mi .dx = 0 ;
244
249
mouseScrollInput .mi .dy = 0 ;
245
250
mouseScrollInput .mi .dwFlags = MOUSEEVENTF_WHEEL ;
246
251
mouseScrollInput .mi .time = 0 ;
247
252
mouseScrollInput .mi .dwExtraInfo = 0 ;
248
253
mouseScrollInput .mi .mouseData = WHEEL_DELTA * scrollDirection * cleanScrollMagnitude ;
249
- SendInput(1, &mouseScrollInput, sizeof(mouseScrollInput));*/
254
+
255
+ SendInput (1 , & mouseScrollInput , sizeof (mouseScrollInput ));
256
+
250
257
#endif
251
258
}
252
259
0 commit comments