NSEvent和魔术鼠标 [英] NSEvent and Magic Mouse
问题描述
如何区分事件-(void)scrollWheel:(NSEvent *)event
是由魔术鼠标还是触控板触发的?
How do I distinguish whether the event -(void)scrollWheel:(NSEvent *)event
was triggered by a Magic Mouse or a trackpad?
我问这个问题的原因是因为我想在使用触控板时为滚动事件分配不同的操作,因为用户可以捏合以放大触控板.但是,在魔术鼠标上,用户无法轻易捏住,因此我想使用滚动功能来代替捏住.
The reason I'm asking this question is because I want to assign a different action to the scrolling event when a trackpad is used because the user can pinch to zoom on the trackpad. On the magic mouse, however, the user can't pinch easily, so I want to use the scrolling function as a substitute for pinching.
我可以使用此行来区分普通鼠标和魔术鼠标:
I can distinguish between a normal mouse and a Magic Mouse using this line:
if (([event momentumPhase] != NSEventPhaseNone) || [event phase] != NSEventPhaseNone)
但是,触控板和Magic Mouse均通过了此测试.
However this test is passed for both, trackpad and Magic Mouse.
推荐答案
我能够使用NSEvent的子类型来区分鼠标(不是Magic Mouse鼠标,但我怀疑它仍然可以工作)上的滚轮和触控板:
I was able to distinguish between a scroll wheel on a mouse (not a Magic Mouse, but I suspect it will still work) and a trackpad using NSEvent's subtype:
enum {
NSMouseEventSubtype = NX_SUBTYPE_DEFAULT,
NSTabletPointEventSubtype = NX_SUBTYPE_TABLET_POINT,
NSTabletProximityEventSubtype = NX_SUBTYPE_TABLET_PROXIMITY
NSTouchEventSubtype = NX_SUBTYPE_MOUSE_TOUCH
};
这篇关于NSEvent和魔术鼠标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!