views:

145

answers:

2

Hello,

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

A: 

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
Rob Keniger
A: 

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?

Rok