Setting NSbutton's keyEquivalentModifierMask doesn't work for control key on macOS 10.15

import Cocoa

class ViewController: NSViewController {



    @IBOutlet var button: NSButton!

    override func viewDidLoad() {

        super.viewDidLoad()

        button.keyEquivalent = "m"

        button.keyEquivalentModifierMask = [.control]

        // Do any additional setup after loading the view.

    }



    override var representedObject: Any? {

        didSet {

        // Update the view, if already loaded.

        }

    }



    @IBAction func buttonclicked(_ sender: NSButton) {

        debugPrint("cliked")

    }
}

but the debug shows that keyEquivalentModifierMask was not set properly

button.keyEquivalentModifierMask NSEvent.ModifierFlags [.command]

That code works for me.

You'll need to debug this further. Perhaps your button's action is not connected to the "buttonClicked" function? Or, if this button is in a window with (say) a text field, and the text field is first responder, Control-M is likely going to be treated as an attempt to type in the text field, not as a keyboard shortcut for the button.

Setting NSbutton's keyEquivalentModifierMask doesn't work for control key on macOS 10.15
 
 
Q