开发者

Is there a way to trigger gesture events on Mac OS X?

开发者 https://www.devze.com 2022-12-23 21:13 出处:网络
I want to trigger multitouch gesture events on Mac OS X. Is there a way to do this? Mouse or keyboard events can be triggered with CGEventCreateMouseEvent and CGEventCreateKeyboardEvent. Is there simi

I want to trigger multitouch gesture events on Mac OS X. Is there a way to do this? Mouse or keyboard events can be triggered with CGEventCreateMouseEvent and CGEventCreateKeyboardEvent. Is there similar low level function for multitouch events?

Rok


Your suggestion is not working. I've tried this code:

- (void)rotateWithEvent:(NSEvent *)event {
    NSLog(@"ROTATE");
}
-(IBAction)button:(id)sender {
    CGEventSourceRef eventSource = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
    CGEventRef event = CGEventCreate(eventSource);
    CGEventSetType(event, NSEventTypeRotate);
    CGEventPost(kCGHI开发者_Python百科DEventTap, event);
    NSLog(@"POST EVENT");
}

But function rotateWithEvent never gets called. Am I doing something wrong?


You could probably use CGEventCreate to create a gesture event. The event types "officially" defined for CGEventCreate don't include gesture event types, but you could pass in the values defined in NSEvent.h:

NSEventTypeGesture
NSEventTypeMagnify
NSEventTypeSwipe
NSEventTypeRotate
NSEventTypeBeginGesture
NSEventTypeEndGesture

The values for non-gesture types seem to map directly to the kCGEvent<TYPE> values in CGEventTypes.h so it's reasonable to expect the gesture event types will work:

CGEventSourceRef eventSource = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
CGEventRef event = CGEventCreate(eventSource);
CGEventSetType(event, NSEventTypeMagnify);
//continue to set up the event


I wonder if you try posting a NSEventTypeBeginGesture before posting the rotate event?

0

精彩评论

暂无评论...
验证码 换一张
取 消