NSStatusItem 不是键盘可导航的

NSStatusItem not keyboard navigable

我已经为我的应用程序创建了一个 NSStatusItem,但希望它在使用 Control+F8 (Control+fn+f8) 时可以导航,就像系统项一样。

在导航序列中莫名其妙地跳过了状态项。是否有接受第一响应者的秘密握手或为此需要做的事情?

这基本上是我为该项目准备的所有设置代码:

statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(28)
statusItem.menu = menu
statusItem.button?.image = NSImage(named: "menuIcon")

我在 quoara.com 上发现了一个类似的问题:http://www.quora.com/Why-cant-I-focus-third-party-icons-in-the-status-menu-area-on-OS-X-with-a-keyboard-shortcut-like-Ctrl-F8-SOLVED

引用科林·巴雷特的话:

The third party items are implemented with a different API (NSStatusItem) than the built-in ones (NSMenuExtra). Note that you can drag to re-arrange the menu extras but not the status items (which always appear to the left of menu extras).

Unfortunately NSMenuExtra is private API and with the Mac App Store you're likely to see less and less apps using it.

Just as an example of third party apps which do support this, you can probably F8 to the MenuMeters icon / graph.

因此,如果您真的想让您的状态菜单项通过键盘可用,您将不得不在 Apple 的私有框架内进行挖掘,但这是一个不稳定的领域,因为它们随时可能更改,恕不另行通知.