Left and right mouse click detection on NSView

In Swift: I created a simple NSView and now I want to perform different functions, depending on which mouse the mouse is pressed on (left or right). how can i detect this?

+5
source share
1 answer

You catch the corresponding mouseDown events

 import Cocoa class MyView : NSView { override func mouseDown(theEvent : NSEvent) { println("left mouse") } override func rightMouseDown(theEvent : NSEvent) { println("right mouse") } } 

See NSResponder for more details.

Swift 4

 import Cocoa class MyView : NSView { override func mouseDown(with theEvent: NSEvent) { print("left mouse") } override func rightMouseDown(with theEvent: NSEvent) { print("right mouse") } } 
+12
source

Source: https://habr.com/ru/post/1212135/


All Articles