Skip to content

UIWindow: isKeyWindow property ​

The isKeyWindow property indicates whether this window is the key window: input events without a location, such as keyboard input, go to it.

Value ​

A boolean.

ValueMeaning
trueThis window is the key window
falseIt isn't
  • Read-only; assigning to it throws TypeError.
  • It is true after makeKeyAndVisible() is called.
  • When it changes, becomekey or resignkey fires.
  • Accessing it before the window has been placed in a scene throws TypeError.

Examples ​

js
application.addEventListener('sceneconnect', (e) => {
  const win = new UIWindow(e.scene);
  win.rootViewController = new UIViewController();
  console.log(win.isKeyWindow);
  win.makeKeyAndVisible();
  console.log(win.isKeyWindow);
});

Result: First prints false, then true. The first value is not verified in the simulator.

Corresponding iOS API ​

UIWindow.keyWindow (isKeyWindow in Swift).

See also ​