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 using CGEventCreateMouseEvent and CGEventCreateKeyboardEvent. Is there a similar low-level feature for multitouch events?

Rok


Your offer does not work. I 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 the rotateWithEvent function is never called. Am I doing something wrong?

+7
events gesture multi-touch macos
source share
2 answers

You could use CGEventCreate to create a gesture event. The "officially" event types defined for CGEventCreate do not include gesture event types, but you can pass the values ​​defined in NSEvent.h :

 NSEventTypeGesture NSEventTypeMagnify NSEventTypeSwipe NSEventTypeRotate NSEventTypeBeginGesture NSEventTypeEndGesture 

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

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

I wonder if you are trying to send an NSEventTypeBeginGesture before posting a rotation event?

0
source share

All Articles