我试图在OS X上实现触摸手势事件的模拟/生成。我尝试这样的事情,但它不起作用:
void touch_begin_gesture(float x, float y) {
/**
* create a new empty Quartz event
*/
CGEventRef begin_gesture_event = CGEventCreate(NULL);
/**
* fill created Quartz event
*/
CGEventSetType(begin_gesture_event, TouchEventTypeBeginGesture);
CGEventSetLocation(begin_gesture_event, CGPointMake(x, y));
/**
* post a Quartz event into the event stream at a specified location.
*/
CGEventPost(kCGHIDEventTap, begin_gesture_event);
/**
* release Quartz event
*/
CFRelease(begin_gesture_event);
}
void touch_end_gesture(float x, float y) {
/**
* create a new empty Quartz event
*/
CGEventRef end_gesture_event = CGEventCreate(NULL);
/**
* fill created Quartz event
*/
CGEventSetType(end_gesture_event, TouchEventTypeEndGesture);
CGEventSetLocation(end_gesture_event, CGPointMake(x, y));
/**
* post a Quartz event into the event stream at a specified location.
*/
CGEventPost(kCGHIDEventTap, end_gesture_event);
/**
* release Quartz event
*/
CFRelease(end_gesture_event);
}
void touch_pinch_gesture_at(float magnification, float x, float y) {
/**
* create a new empty Quartz event
*/
CGEventRef magnify_gesture_event = CGEventCreate(NULL);
/**
* fill created Quartz event
*/
CGEventSetType(magnify_gesture_event, TouchEventTypeMagnify);
CGEventSetLocation(magnify_gesture_event, CGPointMake(x, y));
/**
* post a Quartz event into the event stream at a specified location.
*/
CGEventPost(kCGHIDEventTap, magnify_gesture_event);
/**
* release Quartz event
*/
CFRelease(magnify_gesture_event);
}
以下是常数:
enum {
TouchEventTypeGesture = 29,
TouchEventTypeMagnify = 30, // pinch
TouchEventTypeSwipe = 31, // swipe
TouchEventTypeRotate = 18, // rotate
TouchEventTypeBeginGesture = 19,
TouchEventTypeEndGesture = 20,
TouchEventTypeSmartMagnify = 32,
TouchEventTypeQuickLook = 33,
TouchEventTypePressure = 34
};
void touch_begin_gesture(float x, float y);
void touch_end_gesture(float x, float y);
void touch_pinch_gesture(float magnification);
void touch_pinch_gesture_at(float magnification, float x, float y);
我使用这个调用:
int main() {
touch_begin_gesture(350, 350);
touch_pinch_gesture_at(1.5, 400, 400);
touch_end_gesture(450, 450);
return 0;
}
我认为这样的触摸事件是如何产生的?如何设置此放大,旋转,滑动方向值。有什么文件吗?有人试过这个吗?我发现stackoverflow类似的问题,但没有正确的答案而且更老。如果没有Objective-C,我可以用清晰的C语言实现吗?