当前位置: 首页>>代码示例>>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;未经允许,请勿转载。