小编APr*_*mer的帖子

Mac Cocoa:如何区分NSScrollWheel事件是来自鼠标还是触控板?

在我的应用程序中,我希望滚动发生,只有鼠标滚轮动作而不是触控板上的两个手指动作.基本上,我试图确定是否从鼠标或触控板生成scrollWheelEvent,内部 - (void)scrollWheel:(NSEvent*)theEvent方法.据我所知,到目前为止,似乎没有直接的方法来实现这一目标.

我尝试了将boolean变量设置为true和false in - (void)beginGestureWithEvent:(NSEvent*)event; 和 - (void)endGestureWithEvent:(NSEvent*)事件; 但这不是一个解决方案,因为在调用endGestureWithEvent:方法之后,会多次调用scrollWheel:方法.

这是我的代码:

    $BOOL fromTrackPad = NO;

    -(void)beginGestureWithEvent:(NSEvent *)event;
    {
        fromTrackPad = YES;    
    }

    -(void) endGestureWithEvent:(NSEvent *)event;
    {
        fromTrackPad = NO;    
    }

    - (void)scrollWheel:(NSEvent *)theEvent
    {
       if(!fromTrackPad)
       {
          //then do scrolling
       }
       else 
       {
         //then don't scroll
       }
    }
Run Code Online (Sandbox Code Playgroud)

我知道这是不标准的,但这是我的要求.有谁知道这样做的方法?谢谢!

cocoa trackpad nsevent

7
推荐指数
2
解决办法
4112
查看次数

标签 统计

cocoa ×1

nsevent ×1

trackpad ×1