NSEvent and Magic Mouse

风格不统一 提交于 2019-12-10 11:40:07

问题


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)

However this test is passed for both, trackpad and Magic Mouse.


回答1:


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
};



回答2:


You should handle scrollWheel for the Magic Mouse and add a NSMagnificationGestureRecognizer for the pinch gesture on the trackpad. The two do not conflict with each-other but the swipe-scroll on the trackpad will trigger scrollWheel.



来源:https://stackoverflow.com/questions/14461529/nsevent-and-magic-mouse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!