當前位置: 首頁>>代碼示例>>C++>>正文


C++ CGEventCreateMouseEvent函數代碼示例

本文整理匯總了C++中CGEventCreateMouseEvent函數的典型用法代碼示例。如果您正苦於以下問題:C++ CGEventCreateMouseEvent函數的具體用法?C++ CGEventCreateMouseEvent怎麽用?C++ CGEventCreateMouseEvent使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了CGEventCreateMouseEvent函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: sendNativeMouseButtonEvent_Quartz

Qt::Native::Status sendNativeMouseButtonEvent_Quartz(const QNativeMouseButtonEvent &event)
{
    CGPoint pos;
    pos.x = event.globalPos.x();
    pos.y = event.globalPos.y();

    CGEventType type = kCGEventNull;
    if (event.button == Qt::LeftButton)
        type = (event.clickCount > 0) ? kCGEventLeftMouseDown : kCGEventLeftMouseUp;
    else if (event.button == Qt::RightButton)
        type = (event.clickCount > 0) ? kCGEventRightMouseDown : kCGEventRightMouseUp;
    else
        type = (event.clickCount > 0) ? kCGEventOtherMouseDown : kCGEventOtherMouseUp;

    // The mouseButton argument to CGEventCreateMouseEvent() is ignored unless the type
    // is kCGEventOtherSomething, so defaulting to kCGMouseButtonLeft is fine.
    CGMouseButton mouseButton = (type == kCGEventOtherMouseDown || type == kCGEventOtherMouseUp) ?
        kCGMouseButtonCenter : kCGMouseButtonLeft;

    CGEventRef e = CGEventCreateMouseEvent(0, type, pos, mouseButton);
    setModifiersFromQNativeEvent(e, event);
    CGEventSetIntegerValueField(e, kCGMouseEventClickState, event.clickCount);
    CGEventPost(kCGHIDEventTap, e);
    CFRelease(e);
    return Qt::Native::Success;
}
開發者ID:2gis,項目名稱:2gisqt5android,代碼行數:26,代碼來源:qnativeevents_mac.cpp

示例2: CGEventCreateMouseEvent

bool GTMouseDriver::doubleClick() {

    QPoint mousePos = QCursor::pos();
    CGEventType eventTypeMouseDown = kCGEventLeftMouseDown ;
    CGEventRef eventPress = CGEventCreateMouseEvent(NULL, eventTypeMouseDown, CGPointMake(mousePos.x(), mousePos.y()), 0 /*ignored*/);
    DRIVER_CHECK(eventPress != NULL, "Can't create event");

    CGEventType eventTypeMouseUp = kCGEventLeftMouseUp ;
    CGEventRef eventRelease = CGEventCreateMouseEvent(NULL, eventTypeMouseUp, CGPointMake(mousePos.x(), mousePos.y()), 0 /*ignored*/);
    DRIVER_CHECK(eventRelease != NULL, "Can't create event");

    CGEventPost(kCGSessionEventTap, eventPress);
    GTGlobals::sleep(0); // don't touch, it's Mac's magic
    CGEventPost(kCGSessionEventTap, eventRelease);
    GTGlobals::sleep(0);

    CGEventSetDoubleValueField(eventPress, kCGMouseEventClickState, 2);
    CGEventSetDoubleValueField(eventRelease, kCGMouseEventClickState, 2);

    CGEventPost(kCGSessionEventTap, eventPress);
    GTGlobals::sleep(0); // don't touch, it's Mac's magic
    CGEventPost(kCGSessionEventTap, eventRelease);
    GTGlobals::sleep(0);

    GTGlobals::sleep(100);

    CFRelease(eventPress);
    CFRelease(eventRelease);

    return true;
}
開發者ID:ugeneunipro,項目名稱:QSpec,代碼行數:31,代碼來源:GTMouseDriverMac.cpp

示例3: CGEventCreateMouseEvent

void XInputSimulatorImplMacOs::mouseMoveRelative(int x, int y)
{
    int newX = this->currentX + x;
    int newY = this->currentY + y;

    if(newX < 0 || newX > this->displayX || newY < 0 || newY > this->displayY )
    {
        std::cout << "mouse moved beyound screensize." << std::endl;
        return;
    }

    std::cout << "newx: " << newX << " newy: " << newY << std::endl;

    CGEventRef mouseEv = CGEventCreateMouseEvent(
                NULL, kCGEventMouseMoved,
                CGPointMake(newX, newY),
                kCGMouseButtonLeft);

    CGEventPost(kCGHIDEventTap, mouseEv);

    CFRelease(mouseEv);

    this->currentX = newX;
    this->currentY = newY;
}
開發者ID:thisispoker,項目名稱:alphapoker,代碼行數:25,代碼來源:xinputsimulatorimplmacos.cpp

示例4: CGEventTypeForMouseButton

bool wxUIActionSimulator::MouseDblClick(int button)
{
    CGEventType downtype = CGEventTypeForMouseButton(button, true);
    CGEventType uptype = CGEventTypeForMouseButton(button, false);
    wxCFRef<CGEventRef> event(
                              CGEventCreateMouseEvent(NULL, downtype, GetMousePosition(), CGButtonForMouseButton(button)));
    
    if ( !event )
        return false;
    
    CGEventSetType(event,downtype);
    CGEventPost(tap, event);
    
    CGEventSetType(event, uptype);
    CGEventPost(tap, event);
    
    CGEventSetIntegerValueField(event, kCGMouseEventClickState, 2);
    CGEventSetType(event, downtype);
    CGEventPost(tap, event);
    
    CGEventSetType(event, uptype);
    CGEventPost(tap, event);
    wxCFEventLoop* loop = dynamic_cast<wxCFEventLoop*>(wxEventLoop::GetActive());
    if (loop)
        loop->SetShouldWaitForEvent(true);
    
    return true;
}
開發者ID:70michal19,項目名稱:dolphin,代碼行數:28,代碼來源:uiaction_osx.cpp

示例5: moveMouse

/**
 * Move the mouse to a specific point.
 * @param point The coordinates to move the mouse to (x, y).
 */
void moveMouse(MMPoint point)
{
#if defined(IS_MACOSX)
	CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
	                                          CGPointFromMMPoint(point),
	                                          kCGMouseButtonLeft);

	calculateDeltas(&move, point);

	CGEventPost(kCGSessionEventTap, move);
	CFRelease(move);
#elif defined(USE_X11)
	Display *display = XGetMainDisplay();
	XWarpPointer(display, None, DefaultRootWindow(display),
	             0, 0, 0, 0, point.x, point.y);
	XSync(display, false);
#elif defined(IS_WINDOWS)
	//Mouse motion is now done using SendInput with MOUSEINPUT. We use Absolute mouse positioning
	#define MOUSE_COORD_TO_ABS(coord, width_or_height) (((65536 * coord) / width_or_height) + (coord < 0 ? -1 : 1))
	point.x = MOUSE_COORD_TO_ABS(point.x, GetSystemMetrics(SM_CXSCREEN));
	point.y = MOUSE_COORD_TO_ABS(point.y, GetSystemMetrics(SM_CYSCREEN));
	INPUT mouseInput;
	mouseInput.type = INPUT_MOUSE;
	mouseInput.mi.dx = point.x;
	mouseInput.mi.dy = point.y;
	mouseInput.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
	mouseInput.mi.time = 0; //System will provide the timestamp
	mouseInput.mi.dwExtraInfo = 0;
	mouseInput.mi.mouseData = 0;
	SendInput(1, &mouseInput, sizeof(mouseInput));

#endif
}
開發者ID:aaron21007,項目名稱:2016,代碼行數:37,代碼來源:mouse.c

示例6: CGGetDisplaysWithPoint

bool MouseMac::moveMouseTo(int x, int y)
{
    UInt32 maxDisplays = 4;
    CGDirectDisplayID displayID[maxDisplays];
    CGDisplayCount c = 0;
    CGDisplayCount *count = &c;
    CGGetDisplaysWithPoint(
                CGPointMake(x, y),
                maxDisplays,
                displayID,
                count);
    if (*count > 0)
    {
        CGEventRef mouseEv = CGEventCreateMouseEvent(
                        NULL, kCGEventMouseMoved,
                        CGPointMake(x, y),
                        kCGMouseButtonLeft);
        CGEventPost(kCGHIDEventTap, mouseEv);
        CFRelease(mouseEv);
        return true;
    }
    else
    {
        return false;
    }
}
開發者ID:MichaelChansn,項目名稱:RemoteControlServer,代碼行數:26,代碼來源:mousemac.cpp

示例7: doubleClick

/**
 * Special function for sending double clicks, needed for Mac OS X.
 * @param button Button to click.
 */
void doubleClick(MMMouseButton button)
{
	
#if defined(IS_MACOSX)

	/* Double click for Mac. */
	const CGPoint currentPos = CGPointFromMMPoint(getMousePos());
	const CGEventType mouseTypeDown = MMMouseToCGEventType(true, button);
	const CGEventType mouseTypeUP = MMMouseToCGEventType(false, button);

	CGEventRef event = CGEventCreateMouseEvent(NULL, mouseTypeDown, currentPos, kCGMouseButtonLeft);  
	
	/* Set event to double click. */						
	CGEventSetIntegerValueField(event, kCGMouseEventClickState, 2);
											
	CGEventPost(kCGHIDEventTap, event);  
																
	CGEventSetType(event, mouseTypeUP);  
	CGEventPost(kCGHIDEventTap, event);  

	CFRelease(event); 

#else

	/* Double click for everything else. */
	clickMouse(button);
	microsleep(200);
	clickMouse(button);
	
#endif
}
開發者ID:bright-spark,項目名稱:robotjs,代碼行數:35,代碼來源:mouse.c

示例8: mouseup

void mouseup(char btn) {
    CGEventType eventType;
    CGMouseButton button;
    switch (btn) {
        case 'l':
            eventType = kCGEventLeftMouseDown;
            button = kCGMouseButtonLeft;
            break;
        case 'r':
            eventType = kCGEventRightMouseDown;
            button = kCGMouseButtonRight;
            break;
        case 'm':
            eventType = kCGEventOtherMouseDown;
            button = kCGMouseButtonCenter;
            break;
        default:
            eventType = kCGEventNull;
            break;
    }
    
    if (eventType != kCGEventNull) {
        CGEventRef event = CGEventCreateMouseEvent(NULL, eventType, mousePos(), button);
        CGEventPost(kCGHIDEventTap, event);
        CFRelease(event);
    }
}
開發者ID:Aiur,項目名稱:Airtab,代碼行數:27,代碼來源:main.c

示例9: main

int main() {
	int keyCode = 49; //space bar
	srand ( time(NULL) );
	printf("User input coming in 30 seconds\n");
	sleep(27);
	printf("3...\n");
	sleep(1);
	printf("2...\n");
	sleep(1);
	printf("1...\n");
	sleep(1);
	printf("NOW!");
	while(1){
		CGEventRef ourEvent = CGEventCreate(NULL);
		CGPoint point = CGEventGetLocation(ourEvent);
		
	    CGEventRef click1_down = CGEventCreateMouseEvent(
	        NULL, kCGEventLeftMouseDown,
	        point,
	        kCGMouseButtonLeft
	    );
	    CGEventRef click1_up = CGEventCreateMouseEvent(
	        NULL, kCGEventLeftMouseUp,
	        point,
	        kCGMouseButtonLeft
	    );
		
	    CGEventPost(kCGHIDEventTap, click1_down);
	    sleep(0.11);			
	    CGEventPost(kCGHIDEventTap, click1_up);
		
		CFRelease(click1_up);
	    CFRelease(click1_down);
		CFRelease(ourEvent);
		
		sleep(0.89);
		if(rand() % 100 <= 2){	//2% chance
			CGEventRef e = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)keyCode, true);
			CGEventPost(kCGSessionEventTap, e);
			CFRelease(e);
			e = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)keyCode, false);
			CGEventPost(kCGSessionEventTap, e);		
			CFRelease(e);
		}
		sleep(9);
	}
}
開發者ID:jwhitehorn,項目名稱:JWAuc,代碼行數:47,代碼來源:keyboard.c

示例10: MouseMove

	void MouseMove (int x, int y) {
		CGEventRef move = CGEventCreateMouseEvent(
	        NULL, kCGEventMouseMoved,
	        CGPointMake(x, y),
	        kCGMouseButtonLeft // ignored
	    );
	    CGEventPost(kCGHIDEventTap, move);
	    CFRelease(move);
	}
開發者ID:arextar,項目名稱:ghostjs,代碼行數:9,代碼來源:events_mac.c

示例11: MouseUpRight

	void MouseUpRight () {
		CGEventRef mouse_down = CGEventCreateMouseEvent(
	        NULL, kCGEventRightMouseUp,
	        MousePos(),
	        kCGMouseButtonLeft
	    );
	    CGEventPost(kCGHIDEventTap, mouse_down);
	    CFRelease(mouse_down);
	}
開發者ID:arextar,項目名稱:ghostjs,代碼行數:9,代碼來源:events_mac.c

示例12: CGEventCreateMouseEvent

void MouseMac::rightMouseUp()
{
    CGEventRef mouseEv = CGEventCreateMouseEvent(
                NULL, kCGEventRightMouseUp,
                getCursorPositionCGPoint(),
                kCGMouseButtonRight);
    CGEventPost(kCGHIDEventTap, mouseEv);
    CFRelease(mouseEv);
}
開發者ID:MichaelChansn,項目名稱:RemoteControlServer,代碼行數:9,代碼來源:mousemac.cpp

示例13: leftButtonPressed

void leftButtonPressed(int x, int y) {
	CGEventRef pressLeftButton = CGEventCreateMouseEvent(
														 NULL, kCGEventLeftMouseDown,
														 CGPointMake(x, y),
														 kCGMouseButtonLeft
														 );
	
	CGEventPost(kCGHIDEventTap, pressLeftButton);
	CFRelease(pressLeftButton);
}
開發者ID:Muffo,項目名稱:KinectGraffiti,代碼行數:10,代碼來源:libMouseOSX.c

示例14: rightButtonReleased

void rightButtonReleased(int x, int y){
	CGEventRef releaseRightButton = CGEventCreateMouseEvent(
													  NULL, kCGEventRightMouseUp,
													  CGPointMake(x, y),
													  kCGMouseButtonRight
													  );
	
	CGEventPost(kCGHIDEventTap, releaseRightButton);
	CFRelease(releaseRightButton);
}
開發者ID:Muffo,項目名稱:KinectGraffiti,代碼行數:10,代碼來源:libMouseOSX.c

示例15: inputMouseMove

void inputMouseMove(InputContext* ctx, int mouseLButtonState, int x, int y) {
  CGEventRef mouseMove = CGEventCreateMouseEvent(
      NULL, mouseLButtonState == MOUSE_LBUTTON_DOWN ? kCGEventLeftMouseDragged : kCGEventMouseMoved,
      CGPointMake(x, y),
      kCGMouseButtonLeft // ignored
  );

  CGEventPost(kCGHIDEventTap, mouseMove);
  CFRelease(mouseMove);
}
開發者ID:joeferner,項目名稱:camera-multitouch,代碼行數:10,代碼來源:input_osx.cpp


注:本文中的CGEventCreateMouseEvent函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。