# components/keyboard-layout (zidane-ui)

Import: `import { … } from 'zidane-ui'`. Source: [ui/src/components/keyboard-layout.ts](https://github.com/Tahul/zidane/blob/main/ui/src/components/keyboard-layout.ts).

## Functions

### `_resetKeyboardLayout`

Function.

Tests: drop the cached layout (and re-request on next use), or install a fake one.

```ts
function _resetKeyboardLayout(next?: LayoutMapLike | null): void
```

**Parameters**

- `next?` (`LayoutMapLike | null`, default `null`): A layout map to use instead (no request is made then); `null` clears it.

Source: [ui/src/components/keyboard-layout.ts:111](https://github.com/Tahul/zidane/blob/main/ui/src/components/keyboard-layout.ts#L111)

### `layoutKeyLabel`

Function.

How to label spec key `name` on this layout: for a punctuation key whose
physical key types a stand-in (`typesStandIn`), that character, so the
keycap names exactly what the matcher accepts; otherwise `name`.

```ts
function layoutKeyLabel(name: string): string
```

**Parameters**

- `name` (`string`): A binding spec's key name (`[`, `/`, `k`, `Enter`…).

**Returns** `string`

Source: [ui/src/components/keyboard-layout.ts:82](https://github.com/Tahul/zidane/blob/main/ui/src/components/keyboard-layout.ts#L82)

### `typesStandIn`

Function.

Whether `key` (an `event.key` or a layout character) stands in for the
spec key at its physical position: a dead key or a single character other
than printable ASCII (never a named key like `Process`). The one rule shared by the matcher and keycap labels.

```ts
function typesStandIn(key: string): boolean
```

**Parameters**

- `key` (`string`): An `event.key` value or a character from the layout map.

**Returns** `boolean`

Source: [ui/src/components/keyboard-layout.ts:61](https://github.com/Tahul/zidane/blob/main/ui/src/components/keyboard-layout.ts#L61)

### `useKeyboardLayout`

Function.

Re-renders once the keyboard layout is known (for keycap labels).

```ts
function useKeyboardLayout(enabled?: boolean): void
```

**Parameters**

- `enabled?` (`boolean`, default `true`): `false` neither subscribes nor starts loading the layout.

Source: [ui/src/components/keyboard-layout.ts:102](https://github.com/Tahul/zidane/blob/main/ui/src/components/keyboard-layout.ts#L102)

## Constants

### `PUNCTUATION_CODES`

Constant.

Spec character → physical keys. macOS ISO keyboards swap `Backquote` and `IntlBackslash`.

```ts
const PUNCTUATION_CODES: Readonly<Record<string, readonly string[]>>
```

Source: [ui/src/components/keyboard-layout.ts:14](https://github.com/Tahul/zidane/blob/main/ui/src/components/keyboard-layout.ts#L14)
