2

I have an NSCollectionView which lives inside an NSViewController. NSViewController overrides the following:

class myViewController : NSViewController{
    weak var collectionView : NSCollectionView!
    public override keyDown(with event: NSEvent){
         print("Key pressed.")
    } 
}

However, when collectionView.selectable = true, the view controller no longer receives key down events. I have tried this several ways, and in each case I either capture key too many key events (for example when the view controller is not even in focus) or too few (I don't get they key events at all). Please advise.

SamB
  • 1,560
  • 1
  • 13
  • 19
dmann200
  • 529
  • 4
  • 11
  • 1
    It is Swift naming convention to name all classes starting with an uppercase letter – Leo Dabus Sep 09 '21 at 01:49
  • Which key-down events should the collection view handle (arrows?) and which key-down events do you want to receive? – Willeke Sep 09 '21 at 10:36

1 Answers1

-3

KeyDown, keyUp, insertTab, insertText etc. This methods for keyboard click event.

mouseUp, mouseDown, mouseDragged, mouseMoved etc. This methods for mouse click event.

Your mouse event is fired when you click on any point in your application. And when you write text(A to Z, 0 to 9) in any textfield/textview while keyboard event is fired and ctrl, shift, capsLock, tab etc. click fired without write.

Nikunj Gangani
  • 224
  • 2
  • 10