Type Alias Keyboard

Keyboard: {
    addEventListener: (
        type: "active",
        callback: TypedEventListener<KeyboardEvents>,
        options?: TypedEventListenerOptions,
    ) => void;
    removeEventListener: (
        type: "active",
        callback: TypedEventListener<KeyboardEvents>,
    ) => void;
    getElement: () => HTMLTextAreaElement;
    sendInputToLens: (text: string) => void;
    dismiss: () => void;
}

Keyboard is an API enabling lenses to consume and render user-generated text.

Applications that wish to use lenses that expect user-generated text will need to use this API to integrate text input into their user experience.

There are two ways to do this:

  1. Add the provided DOM element (an HTMLTextAreaElement) to the page. When the user updates this element with text, that text will be sent to the currently active lens.
  2. Use the Keyboard.sendInputToLens method to send text strings to the currently active lens directly.

Lenses will also signal to the application when text input is expected -- applications should add an event listener and ensure the user is able to input text when the active event is received.

Type declaration

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

    Get an HTMLTextAreaElement that communicates text to the active Lens.

  • sendInputToLens: (text: string) => void

    Send text to the active Lens. Also updates the provided HTMLTextAreaElement.

  • dismiss: () => void

    Clears the provided HTMLTextAreaElement, and emits the "active" event with active == false, allowing the application to e.g. remove relevant text input elements from the DOM.

cameraKitSession.keyboard.addEventListener('active', ({ detail }) => {
const { element, active } = detail
if (active) document.body.appendChild(element)
else element.remove()
})
MMNEPVFCICPMFPCPTTAAATR