Wire up the Puzzmo on-screen keyboard so mobile players can type without a hardware keyboard.
The runtime shows the keyboard automatically on touch devices when the game calls sdk.keyboard.show().
-
Import defaultKeyboardConfig alongside the SDK:
import { createPuzzmoSDK, defaultKeyboardConfig } from "@puzzmo/sdk"
import type { KeyboardConfig } from "@puzzmo/sdk"
const sdk = createPuzzmoSDK()
-
Show the keyboard when the player focuses an input (e.g. selects a tile or cell).
Start from defaultKeyboardConfig and customize for your game:
sdk.keyboard.show(defaultKeyboardConfig)
sdk.keyboard.show({ ...defaultKeyboardConfig, disabled: usedLetters })
The keyboard is only visible on touch devices; calling show on desktop is a no-op.
-
Hide the keyboard when input is dismissed (tile deselected, game completed, etc.):
sdk.keyboard.hide()
-
Listen for key presses via the SDK event system:
sdk.on("keyboardKeyPress", ({ key }) => {
if (key === "⌫") {
handleBackspace()
} else if (key === "↵") {
handleEnter()
} else {
handleLetter(key)
}
})
The key value is always the raw character from the layout — not the display label from symbols.
-
Keep the keyboard config in sync with game state. Call sdk.keyboard.show() again whenever
the set of valid/invalid keys changes — for example, after each letter is placed:
function onTileSelected(tile) {
sdk.keyboard.show({
...defaultKeyboardConfig,
disabled: getUsedLetters(gameState),
})
}
-
For games that use custom key layouts (multiple panels, special action keys), define the
config with non-letter Unicode tokens for action keys:
const backspace = "⌫"
const enter = "↵"
const keyboardConfig: KeyboardConfig = {
layout: ["qwertyuiop", "asdfghjkl", `${enter}zxcvbnm${backspace}`, undefined],
symbols: { [backspace]: "bsp", [enter]: "Enter" },
highlight: [backspace, enter],
disabled: [],
xl: [],
l: [backspace, enter],
supportsDragCursor: false,
}
sdk.keyboard.show(keyboardConfig)
-
If your game has a spatial input model (e.g. selecting a grid cell by dragging), enable
the drag cursor and handle the additional events:
sdk.keyboard.show({ ...keyboardConfig, supportsDragCursor: true })
sdk.on("keyboardCursorChange", ({ position }) => {
highlightCellAtPosition(position)
})
sdk.on("keyboardCursorEnd", () => {
confirmCellSelection()
})