<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSPanel/becomesKeyOnlyIfNeeded",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSPanel(py)becomesKeyOnlyIfNeeded"
  },
  "title" : "becomesKeyOnlyIfNeeded"
}
-->

# becomesKeyOnlyIfNeeded

A Boolean value that indicates whether the receiver becomes the key window only when needed.

```
var becomesKeyOnlyIfNeeded: Bool { get set }
```

## Discussion

The value of this property is <doc://com.apple.documentation/documentation/Swift/true> when the panel becomes the key window only when keyboard input is required; the value is <doc://com.apple.documentation/documentation/Swift/false> when the panel becomes key when it’s clicked. The default value is <doc://com.apple.documentation/documentation/Swift/false>.

This behavior is not set by default. You should consider setting it only if most user interface elements in the panel aren’t text fields, and if the choices that can be made by entering text can also be made in another way (such as by clicking an item in a list).

If the panel is a non-activating panel, then it becomes key only if the hit view returns <doc://com.apple.documentation/documentation/Swift/true> from [`needsPanelToBecomeKey`](/documentation/AppKit/NSView/needsPanelToBecomeKey). This way, a non-activating panel can control whether it takes keyboard focus.

## See Also

[`needsPanelToBecomeKey`](/documentation/AppKit/NSView/needsPanelToBecomeKey)

A Boolean value indicating whether the view needs its panel to become the key window before it can handle keyboard input and navigation.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)