当前位置: 首页>>代码示例>>C++>>正文


C++ CGEventPost函数代码示例

本文整理汇总了C++中CGEventPost函数的典型用法代码示例。如果您正苦于以下问题:C++ CGEventPost函数的具体用法?C++ CGEventPost怎么用?C++ CGEventPost使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了CGEventPost函数的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: 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

示例4: ofGetElapsedTimeMillis

//--------------------------------------------------------------
void testApp::update(){
    openNIDevice.update();
    
    int holdTime = 300;
    currTime = ofGetElapsedTimeMillis();
    
    if((currTime - keyTime) > holdTime && leftKeyFlag){
        cout << "RELEASE LEFT KEY" << endl;
        CGEventRef b =  CGEventCreateKeyboardEvent(NULL, 123, 0);
        CGEventPost(kCGHIDEventTap, b);
        leftKeyFlag = false;
    }
    
    if((currTime - keyTime) > holdTime && rightKeyFlag){
        cout << "RELEASE RIGHT KEY" << endl;
        CGEventRef f =  CGEventCreateKeyboardEvent(NULL, 124, 0);
        CGEventPost(kCGHIDEventTap, f);
        rightKeyFlag = false;
    }
    
    if((currTime - keyTime) > holdTime && upKeyFlag){
        cout << "RELEASE UP KEY" << endl;
        CGEventRef d =  CGEventCreateKeyboardEvent(NULL, 126, 0);
        CGEventPost(kCGHIDEventTap, d);
        upKeyFlag = false;
 
    }
    
    if (upKeyFlag == 1) {
        leftByRun = 1;
        rightByRun = 1;
    } else {
        leftByRun = 0;
        rightByRun = 0;}
}
开发者ID:XinheF,项目名称:googlemap_of,代码行数:36,代码来源:testApp.cpp

示例5: KwmEmitKeystroke

void KwmEmitKeystroke(modifiers Mod, std::string Key)
{
    CGEventFlags Flags = 0;
    if(Mod.CmdKey)
        Flags |= kCGEventFlagMaskCommand;
    if(Mod.CtrlKey)
        Flags |= kCGEventFlagMaskControl;
    if(Mod.AltKey)
        Flags |= kCGEventFlagMaskAlternate;
    if(Mod.ShiftKey)
        Flags |= kCGEventFlagMaskShift;

    CGKeyCode Keycode;
    bool Result = GetLayoutIndependentKeycode(Key, &Keycode);
    if(!Result)
        Result = KeycodeForChar(Key[0], &Keycode);

    if(Result)
    {
        CGEventRef EventKeyDown = CGEventCreateKeyboardEvent(NULL, Keycode, true);
        CGEventRef EventKeyUp = CGEventCreateKeyboardEvent(NULL, Keycode, false);
        CGEventSetFlags(EventKeyDown, Flags);
        CGEventSetFlags(EventKeyUp, Flags);

        CGEventPost(kCGHIDEventTap, EventKeyDown);
        CGEventPost(kCGHIDEventTap, EventKeyUp);

        CFRelease(EventKeyDown);
        CFRelease(EventKeyUp);
    }
}
开发者ID:JakimLi,项目名称:kwm,代码行数:31,代码来源:keys.cpp

示例6: 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

示例7: CGEventCreateKeyboardEvent

void UBKeyboardButton::sendControlSymbol(int nSymbol)
{
	CGEventRef event1 = CGEventCreateKeyboardEvent(NULL, nSymbol, true);
	CGEventRef event2 = CGEventCreateKeyboardEvent(NULL, nSymbol, false);

	CGEventPost(kCGHIDEventTap, event1);
	CGEventPost(kCGHIDEventTap, event2);
}
开发者ID:199901,项目名称:Sankore-3.1,代码行数:8,代码来源:UBKeyboardPalette_mac.cpp

示例8: SendString

void SendString(CFStringRef str, unsigned delayMS)
{
  //virtual keycodes copied from 10.6 SDK.  Could not find them in 10.4 SDK
  enum { VK_RETURN = 0x24 /*KVK_Return*/, VK_TAB = 0x30 /*kVK_Tab*/, VK_SPACE = 0x31/*kVK_Space*/};
  
  //A list of chars for which we must specify the virtual keycode
  static const CFStringRef specialChars = CFSTR("\n\t ");
  
  static const UniChar verticalTab = CFStringGetCharacterAtIndex(CFSTR("\v"), 0);

  //each keycode must correspond to the correct char in 'specialChars'
  CGKeyCode specialKeyCodes[] = {VK_RETURN, VK_TAB, VK_SPACE };
  
  assert(CFStringGetLength(specialChars) == NumberOf(specialKeyCodes));

  for (unsigned i = 0, len = CFStringGetLength(str); i < len; ++i) {
    //The next char to send
    UniChar c = CFStringGetCharacterAtIndex(str, i);
    
    //throw away 'vertical tab' chars which are only used on Windows to send a shift+tab
    //as a workaround for some issues with IE 
    if (verticalTab == c)
      continue;
    
    //see if we need to specify the virtual keycode for this char
    CGKeyCode vKey = 0; //0 = kVK_ANSI_A, but I don't know of a more appropriate default value
    for (size_t j = 0; j < NumberOf(specialKeyCodes); ++j) {
      if ( CFStringGetCharacterAtIndex(specialChars, j) == c) {
        vKey = specialKeyCodes[j];
        break;
      }
    }
    
    CGEventRef keyDown = CGEventCreateKeyboardEvent(NULL, vKey, true);
    CGEventRef keyUp   = CGEventCreateKeyboardEvent(NULL, vKey, false);
    
    if (keyDown && keyUp) {
      //may be we should not do this if we found the virtual keycode?
      CGEventKeyboardSetUnicodeString(keyDown, 1, &c);
      CGEventKeyboardSetUnicodeString(keyUp, 1, &c);
      
      CGEventPost(kCGSessionEventTap, keyDown);
      CGEventPost(kCGSessionEventTap, keyUp);
      
      pws_os::sleep_ms(delayMS);
      
      CFRelease(keyDown);
      CFRelease(keyUp);
    }
    else {
      if (keyDown) CFRelease(keyDown);
      if (keyUp) CFRelease(keyUp);
      pws_os::IssueError(_T("Out of memory trying to allocate CGEventRef"));
      return;
    }
  }
}
开发者ID:Sp1l,项目名称:pwsafe,代码行数:57,代码来源:macsendstring.cpp

示例9: main

int main() {
    CGEventRef mkey = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)7, true);
    CGEventPost(kCGSessionEventTap, mkey);
    CFRelease(mkey);
    
    CGEventRef fkey = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)7, false);
    CGEventPost(kCGSessionEventTap, fkey);
    CFRelease(fkey);
    return 0;
}
开发者ID:ippeb,项目名称:TetrisBattleBot,代码行数:10,代码来源:x.c

示例10: CGEventPost

void UBKeyboardButton::sendUnicodeSymbol(KEYCODE keycode)
{
    if (keycode.modifier)
		CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(NULL, 56, true));
    CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(NULL, keycode.code, true));
    CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(NULL, keycode.code, false));
    if (keycode.modifier)
		CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(NULL, 56, false));
	
}
开发者ID:199901,项目名称:Sankore-3.1,代码行数:10,代码来源:UBKeyboardPalette_mac.cpp

示例11: sendPress

void sendPress(int kc) {

 CGEventSourceRef src = NULL;
//    CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
	CGEventRef down, up;
	down = CGEventCreateKeyboardEvent(src,(CGKeyCode)kc, true);
	up = CGEventCreateKeyboardEvent(src,(CGKeyCode)kc, false);
	CGEventPost(kCGSessionEventTap, down);
	CGEventPost(kCGSessionEventTap, up);
	CFRelease(down);
	CFRelease(up);

}
开发者ID:naveenarun,项目名称:Practice_Projects,代码行数:13,代码来源:ye_typer.cpp

示例12: CGEventSourceCreate

void Utilities::PostKey(CGKeyCode key)
{
    CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
    
    CGEventRef keyDown = CGEventCreateKeyboardEvent(source, key, TRUE);
    CGEventRef keyUp = CGEventCreateKeyboardEvent(source, key, FALSE);
    
    CGEventPost(kCGAnnotatedSessionEventTap, keyDown);
    CGEventPost(kCGAnnotatedSessionEventTap, keyUp);
    
    CFRelease(keyUp);
    CFRelease(keyDown);
    CFRelease(source);
}
开发者ID:ichenjia,项目名称:LeapPoint,代码行数:14,代码来源:Utilities.cpp

示例13: 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

示例14: 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

示例15: CGEventCreateKeyboardEvent

void XInputSimulatorImplMacOs::keyUp(int key)
{
    CGKeyCode keycode = key;
    CGEventRef commandUp = CGEventCreateKeyboardEvent(NULL, keycode, false);
    CGEventPost(kCGAnnotatedSessionEventTap, commandUp);
    CFRelease(commandUp);
}
开发者ID:thisispoker,项目名称:alphapoker,代码行数:7,代码来源:xinputsimulatorimplmacos.cpp


注:本文中的CGEventPost函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。