Type alias Keyboard

Keyboard: {
    addEventListener: ((type, callback, options?) => void);
    removeEventListener: ((type, callback) => void);
    getElement: (() => HTMLTextAreaElement);
    sendInputToLens: ((text) => 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 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, callback, options?) => void)
      • (type, callback, options?): void
      • Parameters

        • type: "active"
        • callback: TypedEventListener<KeyboardEvents>
        • Optional options: TypedEventListenerOptions

        Returns void

  • removeEventListener: ((type, callback) => void)
      • (type, callback): void
      • Parameters

        Returns void

  • getElement: (() => HTMLTextAreaElement)
      • (): HTMLTextAreaElement
      • Get an HTMLTextAreaElement that communicates text to the active Lens.

        Returns HTMLTextAreaElement

  • sendInputToLens: ((text) => void)
      • (text): void
      • Send text to the active Lens. Also updates the provided HTMLTextAreaElement.

        Parameters

        • text: string

          String to render. This can include escape sequences, such as the newline character ( \n ) for multi-line input.

        Returns void

  • dismiss: (() => void)
      • (): 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.

        Returns void

Example

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

Generated using TypeDoc