Interface Keyboard

The Keyboard API enables applications to handle text input requests triggered by lenses.

Lenses can request a keyboard display by emitting an active event. The application is responsible for displaying a keyboard UI in response to this event.

As users type, the application sends the typed text back to the lens using Keyboard.sendInputToLens, allowing the lens to display the text accordingly.

Lenses can also request the keyboard to be dismissed. When this happens, the application receives an event and should remove the displayed keyboard UI.

cameraKitSession.keyboard.addEventListener('active', ({ detail }) => {
const { active, text } = detail;
if (active) {
showKeyboard(text, (newText) => cameraKitSession.keyboard.sendInputToLens(newText));
} else {
hideKeyboard();
}
});
interface Keyboard {
    addEventListener: (
        type: "active",
        callback: TypedEventListener<KeyboardEvents>,
        options?: TypedEventListenerOptions,
    ) => void;
    removeEventListener: (
        type: "active",
        callback: TypedEventListener<KeyboardEvents>,
    ) => void;
    sendInputToLens: (text: string) => void;
    dismiss: () => void;
    getElement: () => HTMLTextAreaElement;
}

Properties

addEventListener: (
    type: "active",
    callback: TypedEventListener<KeyboardEvents>,
    options?: TypedEventListenerOptions,
) => void

Adds an event listener for keyboard-related events.

Type declaration

    • (
          type: "active",
          callback: TypedEventListener<KeyboardEvents>,
          options?: TypedEventListenerOptions,
      ): void
    • Parameters

      • type: "active"

        The type of event to listen for (e.g., "active").

      • callback: TypedEventListener<KeyboardEvents>

        Function that handles the event.

      • Optionaloptions: TypedEventListenerOptions

        Additional options for event listener behavior (optional).

      Returns void

removeEventListener: (
    type: "active",
    callback: TypedEventListener<KeyboardEvents>,
) => void

Removes a previously added event listener.

Type declaration

    • (type: "active", callback: TypedEventListener<KeyboardEvents>): void
    • Parameters

      • type: "active"

        The type of event to remove.

      • callback: TypedEventListener<KeyboardEvents>

        The event listener function to remove.

      Returns void

sendInputToLens: (text: string) => void

Sends a string of text to the active lens. The application should use this method to provide user-typed input to the lens for display.

Type declaration

    • (text: string): void
    • Parameters

      • text: string

        The text to send to the lens. Supports escape sequences (e.g., \n for multiline input).

      Returns void

dismiss: () => void

Dismisses the keyboard, clears the text input, and triggers an active event with active: false. Applications can use this to remove on-screen text input elements when input is no longer needed.

getElement: () => HTMLTextAreaElement

Clients apps are responsible to create keyboard UI.

MMNEPVFCICPMFPCPTTAAATR