有没有办法在 Mac OS X 上触发手势事件?
我想在 Mac OS X 上触发多点触控手势事件。有办法做到这一点吗?鼠标或键盘事件可以通过 CGEventCreateMouseEvent 和 CGEventCreateKeyboardEvent 触发。多点触控事件是否有类似的低级功能?
Rok
您的建议不起作用。我试过这段代码: <代码>
- (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");
}
但函数rotateWithEvent永远不会被调用。我做错了什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能可以使用 CGEventCreate 来创建手势事件。为
CGEventCreate
“官方”定义的事件类型不包括手势事件类型,但您可以传入NSEvent.h
中定义的值:非手势的值类型似乎直接映射到
CGEventTypes.h
中的kCGEvent
值,因此可以合理地预期手势事件类型将起作用:You could probably use
CGEventCreate
to create a gesture event. The event types "officially" defined forCGEventCreate
don't include gesture event types, but you could pass in the values defined inNSEvent.h
:The values for non-gesture types seem to map directly to the
kCGEvent<TYPE>
values inCGEventTypes.h
so it's reasonable to expect the gesture event types will work:我想知道您是否在发布旋转事件之前尝试发布 NSEventTypeBeginGesture ?
I wonder if you try posting a NSEventTypeBeginGesture before posting the rotate event?