# useKeyLockState

<!-- DO NOT EDIT: this page is autogenerated from the type comments -->

```ts
function useKeyLockState(key): boolean | null;
```

Defined in: [useKeyLockState.ts:31](https://github.com/TanStack/hotkeys/blob/main/packages/preact-hotkeys/src/useKeyLockState.ts#L31)

Preact hook that returns whether a lock key, such as Caps Lock, is on.

Lock keys toggle instead of being held, so this reads the lock state that
the browser reports on key and mouse events. It returns `null` until the
user presses a key, clicks, or moves the mouse, after the window loses
focus or the page is hidden, and always for Num Lock and Scroll Lock on macOS and iOS.

## Parameters

### key

`LockKey`

`'CapsLock'`, `'NumLock'`, or `'ScrollLock'`

## Returns

`boolean` \| `null`

`true` when the lock is on, `false` when it is off, or `null`

## Example

```tsx
function PasswordField() {
  const capsLock = useKeyLockState('CapsLock')

  return (
    <label>
      Password
      <input type="password" />
      {capsLock && <span role="status">Caps Lock is on</span>}
    </label>
  )
}
```
