Using Sequoia 15.1. No matter what combination of keyboard shortcuts I select, none of them work.
ShowFilesMenu = New MyCocoaMenuItemMBS
ShowFilesMenu.CreateMenuItem "Show Files"
ShowFilesMenu.ID = 1
ShowFilesMenu.tag = 96
ShowFilesMenu.KeyEquivalent = "y"
ShowFilesMenu.KeyEquivalentModifierMask = NSCommandKeyMask + NSAlternateKeyMask + NSControlKeyMask// command-option-control-Y
m.AddItem ShowFilesMenu
Var a As String = ShowFilesMenu.userKeyEquivalent
Log("ShowFilesMenu.userKeyEquivalent = *" + a + "* " + a.Length.ToString)
The log result is: “ShowFilesMenu.userKeyEquivalent = ** 0” which seems to indicate there’s no keyboard shortcut.
I opened and ran the original StatusItem example from MBS, and its keyboard shortcuts don’t work either (Command + F1 now mirrors displays).
Am I missing something, or did Sequoia break something in MyCocoaMenuItemMBS?
userKeyEquivalent: The user-assigned key equivalent for the menu item.
So the user one, not your combination.
I thought .userKeyEquivalent would give you a string showing what the shortcut is. If it’s user-assigned, how would a user assign it?
It still doesn’t explain why KeyEquivalent and KeyEquivalentModifierMask doesn’t work, in my app, or in your original StatusItem example.
While Command-F1 has been remapped by macOS, the other menu command (command-option-shift A) hasn’t, and that in-app keyboard shortcut doesn’t work.
d=new MyCocoaMenuItemMBS
d.CreateMenuItem "Last menu entry",""
d.Enabled=true
d.KeyEquivalent="A"
d.KeyEquivalentModifierMask=NSShiftKeyMask+NSCommandKeyMask+NSAlternateKeyMask // command-option-shift
d.tag=5
In system preferences.
For the hotkey, I can check it myself later next week.
For the moment, I’m using Hotkeys to get around this, but it’d be nice to know why the shortcut KeyEquivalent no longer works.
I tried it today by adding your code to my Menu test project:
Const NSShiftKeyMask=131.072
Const NSControlKeyMask=262144
Const NSAlternateKeyMask=524288
Const NSCommandKeyMask=1048576
// with bullet via constructor
dim n1 as new NSMenuItemMBS(fileDot)
n1.onStateImage = NSImageMBS.imageNamed("NSMenuItemBullet")
n1.KeyEquivalent = "y"
n1.KeyEquivalentModifierMask = NSCommandKeyMask + NSAlternateKeyMask + NSControlKeyMask// command-option-control-Y
and it works for macOS 14.7.1 and 15.1.1 here.
Menu Test.zip (3.2 KB)
We seem to be talking about completely different things. I’m using your StatusItem example for a menubar app:
It creates a menubar app - it does not use the menu bar.
The keyboard shortcut for “Last menu entry” in the menubar app does not work.
The code and example you’re giving me is completely different from the StatusItem example.
Does the keyboard shortcut “⌥⇧⌘A” in the StatusItem example project work for you?
So command-option-control-y jumps back a field here.
I changed to command-option-control-t to test.
Works here for 14.7.1 and 15.1.1 when the menu is open and I press the combination.
If the menu is not open, it doesn’t work for both versions. In that case you need the hotkey Class.
Thanks Christian - you may want to add a note to that example project so others know the Menu has to be open for the keyboard shortcut to work.
It seems a bit redundant at that point - if you’ve clicked on the menu, why switch to the keyboard to type a shortcut when you can just select the menu item?
At least I can use the Hotkeys to execute the shortcuts, and the KeyEquivalent to list them in the menu. I may just have to add a timer or boolean to prevent both shortcuts from executing at the same time if someone has the menu open.