有没有办法在 Mac OS X 上触发手势事件?

发布于 2024-08-25 23:51:48 字数 625 浏览 6 评论 0原文

我想在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时常饿 2024-09-01 23:51:48

您可能可以使用 CGEventCreate 来创建手势事件。为CGEventCreate“官方”定义的事件类型不包括手势事件类型,但您可以传入NSEvent.h中定义的值:

NSEventTypeGesture
NSEventTypeMagnify
NSEventTypeSwipe
NSEventTypeRotate
NSEventTypeBeginGesture
NSEventTypeEndGesture

非手势的值类型似乎直接映射到 CGEventTypes.h 中的 kCGEvent 值,因此可以合理地预期手势事件类型将起作用:

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

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
凉栀 2024-09-01 23:51:48

我想知道您是否在发布旋转事件之前尝试发布 NSEventTypeBeginGesture ?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文