How do I programmatically determine if “Full Keybo

2019-04-29 23:09发布

问题:

Full Keyboard Access mode is enabled or disabled in the Keyboard preference pane - it's referenced here:

Efficiently subclassing standard Cocoa controls

and here:

Disable Full Keyboard Access for App

but nowhere on the web have I found out how to determine, within my app, if Full Keyboard Access is enabled. I'm writing a custom radio control and want to allow tabbing into it iff Full Keyboard Access is on.

回答1:

In Mac OS X 10.6 or higher: -[NSApp isFullKeyboardAccessEnabled].



回答2:

As best I know this is undocumented. It is stored in AppleKeyboardUIMode in NSGlobalDomain:

defaults read -g AppleKeyboardUIMode

It's a bitfield, but I've never seen docs for it. "Full Keyboard Access" seems to toggle bit 1 (value=2).

The short is you should be able to fetch this from NSUserDefaults and bitmask it to find your answer, but it could change.