判断是否所有控件都能获得焦点(即成为第一响应者)

Determine whether all controls can get focus (i.e. become first responder)

我需要检测是否有任何 NSControl,例如 NSButton,可以通过使用 Tab 键获得焦点。

如果用户在键盘/快捷方式/键盘/"Change the way Tab moves focus"下的系统偏好设置中启用了该选项,则可以。

更具体地说,我喜欢将 NSButton 作为第一响应者,但前提是 "all controls can get focus" 模式已启用。也许我可以询问控件是否接受 firstReponder 状态?

我尝试在按钮上调用 acceptsFirstResponder,但是 returns YES 即使它不能通过使用 Tab 键成为 firstReponder,所以这不是正确的方法。

canBecomeKeyView 是您正在寻找的property/method。

来自Cocoa Event Handling Guide, Keyboard Interface Control

The acceptsFirstResponder method controls whether a responder accepts first responder status when its window asks it to (that is, when makeFirstResponder: is called with the responder as the parameter). The canBecomeKeyView method controls whether the Application Kit allows tabbing to a view. It calls acceptsFirstResponder, but it also checks for other information before determining the value to return, such as whether the view is hidden and whether full keyboard access is on.