Skip to content

UIScreenKeyboardEvent ​

UIScreenKeyboardEvent represents the on-screen keyboard appearing, hiding, or changing its position or size.

The three keyboard events of UIScreen are this class. It carries the keyboard's position at the start and end of its animation and the animation's duration, so the UI can move along with the keyboard.

Inheritance: Event → UIScreenKeyboardEvent

Constructor ​

UIScreenKeyboardEvent()

Creates a UIScreenKeyboardEvent. The runtime creates one itself when it fires the events below; app code can use it to build an event object and fire it with dispatchEvent() to try out a listener.

Instance properties ​

Also inherits the properties of Event; the most commonly used are type and target. The properties below are read-only; assigning to them throws TypeError.

PropertyDescription
frame read-onlyThe keyboard position when the animation ends
previousFrame read-onlyThe keyboard position when the animation starts
duration read-onlyThe duration of the keyboard animation

These properties live on the prototype, not on the event object itself: Object.keys(event) and { ...event } don't include them, so read them one by one. See Events with fields.

Events that use this class ​

ObjectEvents
UIScreenkeyboardshow, keyboardhide, keyboardchange

It can't be canceled: cancelable is false, and preventDefault() has no effect. On iPhone the app fills the whole screen, so screen coordinates equal window coordinates.

Examples ​

js
application.addEventListener('sceneconnect', (connect) => {
  connect.scene.screen.addEventListener('keyboardshow', (e) => {
    console.log(e instanceof UIScreenKeyboardEvent, e.frame.y, e.duration);
  });
});

Effect: when the keyboard appears, prints true, the y of the keyboard's top edge, and the animation duration.

Corresponding iOS API ​

ObjCJS
UIKeyboardWillShowNotificationkeyboardshow
UIKeyboardWillHideNotificationkeyboardhide
UIKeyboardWillChangeFrameNotificationkeyboardchange
userInfo[UIKeyboardFrameEndUserInfoKey]event.frame
userInfo[UIKeyboardFrameBeginUserInfoKey]event.previousFrame
userInfo[UIKeyboardAnimationDurationUserInfoKey]event.duration

See also ​