NSCombobox : KeyDown

Does anyone know how to create/intercept the KeyDown event for a NSCombobox?
The problem is the event is consumed by the CB internal Textview , and I so far cannot figure how to attach to that event.

This is not easy.
I made the required code for our NSSearchFieldControlMBS control.
Technically the key events don’t go to the control, but to the textfield inside. So the plugin author needs to subclass that and then replace the default one with the self made one to catch the key events.
Lot’s of work for a little benefit and not much customers asking for it.

Thanks… I knew where the event was being consumed… and articles eluded to the event being exposed… but not been able to find anything… as far as the NSCombobox itself is concerned, I am using a subclass… so that part is a done deal :slight_smile:

The subclass must be done in Objective-C for the NSTextField inside the NSComboBox.

I’m thinking that is less than correct… since the NSTextField can be subclassed entirely in Swift as well

Swift (from a code perspective) relies on almost no ObjC code what so ever… other than adding a “@objC” tag on certain items…but the code following is still Swift

We will get a NSComboBoxControlMBS control in MBS Xojo Plugins. Later today or tomorrow.

And KeyDown/KeyUp events should work.

won’t do me a darn bit of good, but thanks…
two reasons… 1) you know I don’t buy plugins and 2) MBS doesn’t work with Swift :slight_smile:


Have you trying this ?

_evt(_ e:NSEvent) -> NSEvent?
    if e.type == .keyDown
        if let s = e.characters
             print("keydown are ",s)
    return e

// call below in your creation control

    NSEvent.addLocalMonitorForEvents(matching: [.keyDown], handler: _evt)

thanks I’ll see what I can do with that… .looks like Swifts version of “addHandler”