如何调用三指点击,石英事件

时间:2014-10-26 08:24:28

标签: objective-c macos

我试图在OSX上调用三指点击。我了解如何使用Quartz Event使用与此类似的代码进行点击:

CGEventRef tempEventForMouseLocation = CGEventCreate(NULL); // don't mix nspoint and cg point...or else
CGPoint point = CGEventGetLocation(tempEventForMouseLocation);
CFRelease(tempEventForMouseLocation); // relese the event

// peform n tap, single finger
CGEventRef singleFinger_nTapEvent = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown, point, kCGMouseButtonLeft);
CGEventSetIntegerValueField(singleFinger_nTapEvent, kCGMouseEventClickState, numTaps); // 1 for single click

for (int i=0; i < numTaps; i++) {
    CGEventSetType(singleFinger_nTapEvent, kCGEventLeftMouseDown);
    CGEventPost(kCGHIDEventTap, singleFinger_nTapEvent);
    CGEventSetType(singleFinger_nTapEvent, kCGEventLeftMouseUp);
    CGEventPost(kCGHIDEventTap, singleFinger_nTapEvent);
}

CFRelease(singleFinger_nTapEvent); // release the event

用于三指敲击的OSX标准是快速查看。如果我没有必要,我宁愿不实现quicklookwithevent方法,如果可能的话,我宁愿触发三指点击(让操作系统做到这一点)。

我没有多少运气寻找这个,所以任何帮助都会受到赞赏。

更新:

我试图创建quicklook事件,但它给了我错误,因为在创建它时我确信我没有正确输入参数。这就是我现在所拥有的:

NSPoint point = [NSEvent mouseLocation];
NSInteger windowNumber = [[[NSApplication sharedApplication] keyWindow] windowNumber];
NSEvent *quickLookEvent = [NSEvent otherEventWithType:NSEventTypeQuickLook location:point modifierFlags:kNilOptions timestamp:0 windowNumber:windowNumber  context:[NSGraphicsContext currentContext] subtype:NSAppKitDefined data1:0 data2:0];
[[NSApplication sharedApplication] postEvent:quickLookEvent atStart:NO];

0 个答案:

没有答案