How to judge NSEvent from trackpad click, not tap

2019-07-16 04:54发布

问题:

When "tap to click" checked, how judge NSEvent is from trackpad click(pressed down) or tap to click.

- (void)mouseEvent:(NSEvent*)theEvent {
  if ((type == NSLeftMouseUp || type == NSLeftMouseDown) && [theEvent subtype] == NSEventSubtypeTouch) {
    // How to detect touchpad is real pressed?? Not tap to cllick
  }
}

回答1:

To find out if someone only "tap to click" you could use

func pressureChange(with event: NSEvent) 

in your NSViewController on NSView.

If someone only "tap" the function will not be triggered. In case of a click you will get the pressure level on pressure change.

   override func pressureChange(with event: NSEvent) {
        super.pressureChange(with: event)
        print("pressure \(event.pressure)")
    }