@snap/camera-kit
Version:
Camera Kit Web
138 lines (76 loc) • 2.64 kB
Markdown
[**CameraKit Web SDK v1.13.0**](../README.md)
***
[](../globals.md) / 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](Keyboard.md
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.
```ts
cameraKitSession.keyboard.addEventListener('active', ({ detail }) => {
const { active, text } = detail;
if (active) {
showKeyboard(text, (newText) => cameraKitSession.keyboard.sendInputToLens(newText));
} else {
hideKeyboard();
}
});
```
> **addEventListener**: (`type`, `callback`, `options`?) => `void`
Adds an event listener for keyboard-related events.
`"active"`
The type of event to listen for (e.g., "active").
##### callback
[`KeyboardEventListener`](../type-aliases/KeyboardEventListener.md)
Function that handles the event.
##### options?
`TypedEventListenerOptions`
Additional options for event listener behavior (optional).
#### Returns
`void`
***
### removeEventListener()
> **removeEventListener**: (`type`, `callback`) => `void`
Removes a previously added event listener.
`"active"`
The type of event to remove.
[`KeyboardEventListener`](../type-aliases/KeyboardEventListener.md)
The event listener function to remove.
`void`
***
> **sendInputToLens**: (`text`) => `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.
`string`
The text to send to the lens. Supports escape sequences (e.g., `\n` for multiline input).
#### Returns
`void`
***
### dismiss()
> **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.
`void`
***
> **getElement**: () => `HTMLTextAreaElement`
`HTMLTextAreaElement`
Clients apps are responsible to create keyboard UI.