Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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(kCGHIDEventTap, event);
    NSLog(@"POST EVENT");
}

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

like image 421
Rok Avatar asked Mar 21 '10 14:03

Rok


1 Answers

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
like image 176
Rob Keniger Avatar answered Oct 17 '22 18:10

Rob Keniger