@@ -232,71 +232,74 @@ void doubleClick(MMMouseButton button)
232
232
#endif
233
233
}
234
234
235
- /**
236
- * Function used to scroll the screen in the required direction.
237
- * This uses the magnitude to scroll the required amount in the direction.
238
- * TODO Requires further fine tuning based on the requirements.
239
- */
240
- void scrollMouse (int scrollMagnitude , MMMouseWheelDirection scrollDirection )
235
+ void scrollMouse (MMPoint scroll )
241
236
{
242
- #if defined(IS_WINDOWS )
237
+ #if defined(IS_WINDOWS )
243
238
// Fix for #97 https://github.com/octalmage/robotjs/issues/97,
244
239
// C89 needs variables declared on top of functions (mouseScrollInput)
245
- INPUT mouseScrollInput ;
246
- #endif
247
-
248
- /* Direction should only be considered based on the scrollDirection. This
249
- * Should not interfere. */
250
- int cleanScrollMagnitude = abs (scrollMagnitude );
251
- if (!(scrollDirection == DIRECTION_UP || scrollDirection == DIRECTION_DOWN ))
252
- {
253
- return ;
254
- }
240
+ INPUT mouseScrollInputH ;
241
+ INPUT mouseScrollInputV ;
242
+ #endif
255
243
256
- /* Set up the OS specific solution */
257
- #if defined( __APPLE__ )
244
+ /* Direction should only be considered based on the scrollDirection. This
245
+ * Should not interfere. */
258
246
259
- CGWheelCount wheel = 1 ;
260
- CGEventRef event ;
247
+ /* Set up the OS specific solution */
248
+ #if defined( __APPLE__ )
261
249
262
- /* Make scroll magnitude negative if we're scrolling down. */
263
- cleanScrollMagnitude = cleanScrollMagnitude * scrollDirection ;
250
+ CGEventRef event ;
264
251
265
- event = CGEventCreateScrollWheelEvent (NULL , kCGScrollEventUnitLine , wheel , cleanScrollMagnitude , 0 );
252
+ event = CGEventCreateScrollWheelEvent (NULL , kCGScrollEventUnitPixel , 2 , scroll . y , scroll . x );
266
253
CGEventPost (kCGHIDEventTap , event );
267
254
268
- #elif defined(USE_X11 )
255
+ CFRelease (event );
256
+
257
+ #elif defined(USE_X11 )
269
258
270
- int x ;
271
- int dir = 4 ; /* Button 4 is up, 5 is down. */
259
+ int ydir = 4 ; /* Button 4 is up, 5 is down. */
260
+ int xdir = 6 ;
272
261
Display * display = XGetMainDisplay ();
273
262
274
- if (scrollDirection == DIRECTION_DOWN )
275
- {
276
- dir = 5 ;
263
+ if (scroll .y < 0 ){
264
+ ydir = 5 ;
277
265
}
278
-
279
- for (x = 0 ; x < cleanScrollMagnitude ; x ++ )
280
- {
281
- XTestFakeButtonEvent (display , dir , 1 , CurrentTime );
282
- XTestFakeButtonEvent (display , dir , 0 , CurrentTime );
266
+ if (scroll .x < 0 ){
267
+ xdir = 7 ;
283
268
}
284
269
285
- XFlush (display );
270
+ for (int x = 0 ; x < abs (scroll .x ); x ++ ) {
271
+ XTestFakeButtonEvent (display , xdir , 1 , CurrentTime );
272
+ XTestFakeButtonEvent (display , xdir , 0 , CurrentTime );
273
+ }
286
274
287
- #elif defined(IS_WINDOWS )
275
+ for (int y = 0 ; y < abs (scroll .y ); y ++ ) {
276
+ XTestFakeButtonEvent (display , ydir , 1 , CurrentTime );
277
+ XTestFakeButtonEvent (display , ydir , 0 , CurrentTime );
278
+ }
288
279
289
- mouseScrollInput .type = INPUT_MOUSE ;
290
- mouseScrollInput .mi .dx = 0 ;
291
- mouseScrollInput .mi .dy = 0 ;
292
- mouseScrollInput .mi .dwFlags = MOUSEEVENTF_WHEEL ;
293
- mouseScrollInput .mi .time = 0 ;
294
- mouseScrollInput .mi .dwExtraInfo = 0 ;
295
- mouseScrollInput .mi .mouseData = WHEEL_DELTA * scrollDirection * cleanScrollMagnitude ;
280
+ XFlush (display );
296
281
297
- SendInput ( 1 , & mouseScrollInput , sizeof ( mouseScrollInput ));
282
+ #elif defined( IS_WINDOWS )
298
283
299
- #endif
284
+ mouseScrollInputH .type = INPUT_MOUSE ;
285
+ mouseScrollInputH .mi .dx = 0 ;
286
+ mouseScrollInputH .mi .dy = 0 ;
287
+ mouseScrollInputH .mi .dwFlags = MOUSEEVENTF_WHEEL ;
288
+ mouseScrollInputH .mi .time = 0 ;
289
+ mouseScrollInputH .mi .dwExtraInfo = 0 ;
290
+ mouseScrollInputH .mi .mouseData = WHEEL_DELTA * scroll .x ;
291
+
292
+ mouseScrollInputV .type = INPUT_MOUSE ;
293
+ mouseScrollInputV .mi .dx = 0 ;
294
+ mouseScrollInputV .mi .dy = 0 ;
295
+ mouseScrollInputV .mi .dwFlags = MOUSEEVENTF_HWHEEL ;
296
+ mouseScrollInputV .mi .time = 0 ;
297
+ mouseScrollInputV .mi .dwExtraInfo = 0 ;
298
+ mouseScrollInputV .mi .mouseData = WHEEL_DELTA * scroll .y ;
299
+
300
+ SendInput (1 , & mouseScrollInputH , sizeof (mouseScrollInputH ));
301
+ SendInput (1 , & mouseScrollInputV , sizeof (mouseScrollInputV ));
302
+ #endif
300
303
}
301
304
302
305
/*
0 commit comments