void XInputSimulatorImplMacOs::mouseScrollY(int length) { int scrollDirection = -1; // 1 down -1 up if(length < 0){ length *= -1; scrollDirection *= -1; } //length *= 100; for(int cnt = 0; cnt < length; cnt++){ std::cout << "scroll y mac" << std::endl; CGEventRef scrollEv = CGEventCreateScrollWheelEvent ( NULL, kCGScrollEventUnitLine, // kCGScrollEventUnitLine //kCGScrollEventUnitPixel 1, //CGWheelCount 1 = y 2 = xy 3 = xyz scrollDirection); // length of scroll from -10 to 10 higher values lead to undef behaviour CGEventPost(kCGHIDEventTap, scrollEv); CFRelease(scrollEv); //sleep(1); } }
static inline void ScrollUp() { CGEventRef scroll = CGEventCreateScrollWheelEvent( NULL, kCGScrollEventUnitLine, 1, 4); CGEventPost(kCGHIDEventTap, scroll); CFRelease(scroll); }
/** * Function used to scroll the screen in the required direction. * This uses the magnitude to scroll the required amount in the direction. * TODO Requires further fine tuning based on the requirements. */ void scrollMouse(int scrollMagnitude, MMMouseWheelDirection scrollDirection) { /* Direction should only be considered based on the scrollDirection. This * Should not interfere. */ int cleanScrollMagnitude = abs(scrollMagnitude); if (!(scrollDirection == DIRECTION_UP || scrollDirection == DIRECTION_DOWN)) { return; } /* Set up the OS specific solution */ #if defined(__APPLE__) CGWheelCount wheel = 1; CGEventRef event; /* Make scroll magnitude negative if we're scrolling down. */ cleanScrollMagnitude = cleanScrollMagnitude * scrollDirection; event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitLine, wheel, cleanScrollMagnitude, 0); CGEventPost(kCGHIDEventTap, event); #elif defined(USE_X11) int x; int dir = 4; /* Button 4 is up, 5 is down. */ Display *display = XGetMainDisplay(); if (scrollDirection == DIRECTION_DOWN) { dir = 5; } for (x = 0; x < cleanScrollMagnitude; x++) { XTestFakeButtonEvent(display, dir, 1, CurrentTime); XTestFakeButtonEvent(display, dir, 0, CurrentTime); } XFlush(display); #elif defined(IS_WINDOWS) //FIXME: Need to figure out why this code doesn't work on Windows XP. /*INPUT mouseScrollInput; mouseScrollInput.type = INPUT_MOUSE; mouseScrollInput.mi.dx = 0; mouseScrollInput.mi.dy = 0; mouseScrollInput.mi.dwFlags = MOUSEEVENTF_WHEEL; mouseScrollInput.mi.time = 0; mouseScrollInput.mi.dwExtraInfo = 0; mouseScrollInput.mi.mouseData = WHEEL_DELTA * scrollDirection * cleanScrollMagnitude; SendInput(1, &mouseScrollInput, sizeof(mouseScrollInput));*/ #endif }
Qt::Native::Status sendNativeMouseWheelEvent_Quartz(const QNativeMouseWheelEvent &event) { CGPoint pos; pos.x = event.globalPos.x(); pos.y = event.globalPos.y(); CGEventRef e = CGEventCreateScrollWheelEvent(0, kCGScrollEventUnitPixel, 1, 0); CGEventSetIntegerValueField(e, kCGScrollWheelEventDeltaAxis1, event.delta); CGEventSetLocation(e, pos); setModifiersFromQNativeEvent(e, event); CGEventPost(kCGHIDEventTap, e); CFRelease(e); return Qt::Native::Success; }
bool GTMouseDriver::scroll(int value) { CGEventRef event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 1, value > 0 ? 10 : -10); DRIVER_CHECK(event != NULL, "Can't create event"); // Scrolling movement is generally represented by small signed integer values, typically in a range from -10 to +10. // Large values may have unexpected results, depending on the application that processes the event. value = value > 0 ? value : -value; for (int i = 0; i < value; i += 10) { CGEventPost(kCGSessionEventTap, event); GTGlobals::sleep(0); // don't touch, it's Mac's magic } CFRelease(event); return true; }
void MouseMac::mouseScrollVertical(int scrollDirection, int scrollLength) { if (scrollDirection < -10 || scrollDirection == 0 || scrollDirection > 10) { scrollDirection = 1; } scrollDirection = scrollDirection * scrollLength / 100; scrollDirection = (scrollDirection < -10) ? -10 : ((scrollDirection > 10) ? 10 : scrollDirection); CGEventRef scrollEvent = CGEventCreateScrollWheelEvent ( NULL, kCGScrollEventUnitLine, // kCGScrollEventUnitLine //kCGScrollEventUnitPixel 1, //CGWheelCount 1 = y 2 = xy 3 = xyz scrollDirection); // length of scroll from -10 to 10 higher values lead to undef behaviour CGEventPost(kCGHIDEventTap, scrollEvent); CFRelease(scrollEvent); }
void COSXScreen::fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const { if (xDelta != 0 || yDelta != 0) { #if defined(MAC_OS_X_VERSION_10_5) // create a scroll event, post it and release it. not sure if kCGScrollEventUnitLine // is the right choice here over kCGScrollEventUnitPixel CGEventRef scrollEvent = CGEventCreateScrollWheelEvent( NULL, kCGScrollEventUnitLine, 2, mapScrollWheelFromSynergy(yDelta), -mapScrollWheelFromSynergy(xDelta)); CGEventPost(kCGHIDEventTap, scrollEvent); CFRelease(scrollEvent); #else CGPostScrollWheelEvent( 2, mapScrollWheelFromSynergy(yDelta), -mapScrollWheelFromSynergy(xDelta)); #endif } }
void mf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) { float width, height; CGWheelCount wheelCount = 2; UINT32 scroll_x = 0; UINT32 scroll_y = 0; if (flags & PTR_FLAGS_WHEEL) { scroll_y = flags & WheelRotationMask; if (flags & PTR_FLAGS_WHEEL_NEGATIVE) { scroll_y = -(flags & WheelRotationMask) / 392; } else { scroll_y = (flags & WheelRotationMask) / 120; } CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateHIDSystemState); CGEventRef scroll = CGEventCreateScrollWheelEvent(source, kCGScrollEventUnitLine, wheelCount, scroll_y, scroll_x); CGEventPost(kCGHIDEventTap, scroll); CFRelease(scroll); CFRelease(source); } /* /////////////////////////////////////////////// // We dont support horizontal scrolling yet... /////////////////////////////////////////////// else if (flags & PTR_FLAGS_) { scroll_y = flags & WheelRotationMask; if (flags & PTR_FLAGS_WHEEL_NEGATIVE) { scroll_y = -(flags & WheelRotationMask) / 392; } else { scroll_y = (flags & WheelRotationMask) / 120; } CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateCombinedSessionState); CGEventRef scroll = CGEventCreateScrollWheelEvent(source, kCGScrollEventUnitLine, wheelCount, scroll_y, scroll_x); CGEventPost(kCGHIDEventTap, scroll); CFRelease(scroll); CFRelease(source); } */ else { mfInfo * mfi; CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateHIDSystemState); CGEventType mouseType = kCGEventNull; CGMouseButton mouseButton = kCGMouseButtonLeft; mfi = mf_info_get_instance(); //width and height of primary screen (even in multimon setups width = (float) mfi->servscreen_width; height = (float) mfi->servscreen_height; x += mfi->servscreen_xoffset; y += mfi->servscreen_yoffset; if (flags & PTR_FLAGS_MOVE) { if (mfi->mouse_down_left == TRUE) { mouseType = kCGEventLeftMouseDragged; } else if (mfi->mouse_down_right == TRUE) { mouseType = kCGEventRightMouseDragged; } else if (mfi->mouse_down_other == TRUE) { mouseType = kCGEventOtherMouseDragged; } else { mouseType = kCGEventMouseMoved; } CGEventRef move = CGEventCreateMouseEvent(source, mouseType, CGPointMake(x, y), mouseButton // ignored for just movement ); CGEventPost(kCGHIDEventTap, move); CFRelease(move); } if (flags & PTR_FLAGS_BUTTON1) { mouseButton = kCGMouseButtonLeft; if (flags & PTR_FLAGS_DOWN) { mouseType = kCGEventLeftMouseDown; mfi->mouse_down_left = TRUE; } else { mouseType = kCGEventLeftMouseUp; mfi->mouse_down_right = FALSE; } } else if (flags & PTR_FLAGS_BUTTON2) { mouseButton = kCGMouseButtonRight; if (flags & PTR_FLAGS_DOWN) { mouseType = kCGEventRightMouseDown; mfi->mouse_down_right = TRUE; } else { mouseType = kCGEventRightMouseUp; mfi->mouse_down_right = FALSE; } } else if (flags & PTR_FLAGS_BUTTON3) { mouseButton = kCGMouseButtonCenter; if (flags & PTR_FLAGS_DOWN) { mouseType = kCGEventOtherMouseDown; mfi->mouse_down_other = TRUE; } else { mouseType = kCGEventOtherMouseUp; mfi->mouse_down_other = FALSE; } } CGEventRef mouseEvent = CGEventCreateMouseEvent(source, mouseType, CGPointMake(x, y), mouseButton ); CGEventPost(kCGHIDEventTap, mouseEvent); CFRelease(mouseEvent); CFRelease(source); } }
void verticalScroll(int x, int y) { CGEventRef event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 2, y, x); CGEventSetType(event, kCGEventScrollWheel); CGEventPost(kCGSessionEventTap, event); CFRelease(event); }
static void mac_shadow_input_mouse_event(macShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y) { UINT32 scrollX = 0; UINT32 scrollY = 0; CGWheelCount wheelCount = 2; if (flags & PTR_FLAGS_WHEEL) { scrollY = flags & WheelRotationMask; if (flags & PTR_FLAGS_WHEEL_NEGATIVE) { scrollY = -(flags & WheelRotationMask) / 392; } else { scrollY = (flags & WheelRotationMask) / 120; } CGEventSourceRef source = CGEventSourceCreate( kCGEventSourceStateHIDSystemState); CGEventRef scroll = CGEventCreateScrollWheelEvent(source, kCGScrollEventUnitLine, wheelCount, scrollY, scrollX); CGEventPost(kCGHIDEventTap, scroll); CFRelease(scroll); CFRelease(source); } else { CGEventSourceRef source = CGEventSourceCreate( kCGEventSourceStateHIDSystemState); CGEventType mouseType = kCGEventNull; CGMouseButton mouseButton = kCGMouseButtonLeft; if (flags & PTR_FLAGS_MOVE) { if (subsystem->mouseDownLeft) mouseType = kCGEventLeftMouseDragged; else if (subsystem->mouseDownRight) mouseType = kCGEventRightMouseDragged; else if (subsystem->mouseDownOther) mouseType = kCGEventOtherMouseDragged; else mouseType = kCGEventMouseMoved; CGEventRef move = CGEventCreateMouseEvent(source, mouseType, CGPointMake(x, y), mouseButton); CGEventPost(kCGHIDEventTap, move); CFRelease(move); } if (flags & PTR_FLAGS_BUTTON1) { mouseButton = kCGMouseButtonLeft; if (flags & PTR_FLAGS_DOWN) { mouseType = kCGEventLeftMouseDown; subsystem->mouseDownLeft = TRUE; } else { mouseType = kCGEventLeftMouseUp; subsystem->mouseDownLeft = FALSE; } } else if (flags & PTR_FLAGS_BUTTON2) { mouseButton = kCGMouseButtonRight; if (flags & PTR_FLAGS_DOWN) { mouseType = kCGEventRightMouseDown; subsystem->mouseDownRight = TRUE; } else { mouseType = kCGEventRightMouseUp; subsystem->mouseDownRight = FALSE; } } else if (flags & PTR_FLAGS_BUTTON3) { mouseButton = kCGMouseButtonCenter; if (flags & PTR_FLAGS_DOWN) { mouseType = kCGEventOtherMouseDown; subsystem->mouseDownOther = TRUE; } else { mouseType = kCGEventOtherMouseUp; subsystem->mouseDownOther = FALSE; } } CGEventRef mouseEvent = CGEventCreateMouseEvent(source, mouseType, CGPointMake(x, y), mouseButton); CGEventPost(kCGHIDEventTap, mouseEvent); CFRelease(mouseEvent); CFRelease(source); } }
void scrollMouse(int x, int y) { #if defined(IS_WINDOWS) // Fix for #97 https://github.com/octalmage/robotjs/issues/97, // C89 needs variables declared on top of functions (mouseScrollInput) INPUT mouseScrollInputH; INPUT mouseScrollInputV; #endif /* Direction should only be considered based on the scrollDirection. This * Should not interfere. */ /* Set up the OS specific solution */ #if defined(__APPLE__) CGEventRef event; event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 2, y, x); CGEventPost(kCGHIDEventTap, event); CFRelease(event); #elif defined(USE_X11) /* 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){ ydir = 5; } if (x < 0){ xdir = 7; } int xi; int yi; for (xi = 0; xi < abs(x); xi++) { XTestFakeButtonEvent(display, xdir, 1, CurrentTime); XTestFakeButtonEvent(display, xdir, 0, CurrentTime); } for (yi = 0; yi < abs(y); yi++) { XTestFakeButtonEvent(display, ydir, 1, CurrentTime); XTestFakeButtonEvent(display, ydir, 0, CurrentTime); } XSync(display, false); #elif defined(IS_WINDOWS) mouseScrollInputH.type = INPUT_MOUSE; mouseScrollInputH.mi.dx = 0; mouseScrollInputH.mi.dy = 0; mouseScrollInputH.mi.dwFlags = MOUSEEVENTF_HWHEEL; mouseScrollInputH.mi.time = 0; mouseScrollInputH.mi.dwExtraInfo = 0; // Flip x to match other platforms. mouseScrollInputH.mi.mouseData = -x; mouseScrollInputV.type = INPUT_MOUSE; mouseScrollInputV.mi.dx = 0; mouseScrollInputV.mi.dy = 0; mouseScrollInputV.mi.dwFlags = MOUSEEVENTF_WHEEL; mouseScrollInputV.mi.time = 0; mouseScrollInputV.mi.dwExtraInfo = 0; mouseScrollInputV.mi.mouseData = y; SendInput(1, &mouseScrollInputH, sizeof(mouseScrollInputH)); SendInput(1, &mouseScrollInputV, sizeof(mouseScrollInputV)); #endif }
void scrollY(double amount) { CGEventRef event = CGEventCreateScrollWheelEvent(NULL, kCGEventMouseSubtypeDefault, 1, amount); CGEventPost(kCGHIDEventTap, event); CFRelease(event); }