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

2

7

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?

Cadel answered 21/3, 2010 at 14:3 Comment(2)
Has anyone found a solution for this??? I am struggling with a similar problem a couple of days already, but nothing seems to work :(Creath
did you find filed that is needed to be set?Motoring
A
3

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
Antiphlogistic answered 22/3, 2010 at 1:47 Comment(2)
could you give more details about what data to "set up" ?Megen
how to set up this eventMotoring
B
0

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

Busiek answered 25/2, 2012 at 0:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.