# getKeyLockState

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

```ts
function getKeyLockState(key): SvelteKeyLockState;
```

Defined in: [packages/svelte-hotkeys/src/getKeyLockState.svelte.ts:54](https://github.com/TanStack/hotkeys/blob/main/packages/svelte-hotkeys/src/getKeyLockState.svelte.ts#L54)

Svelte function that returns reactive access to 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. Its `value` is `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

[`SvelteKeyLockState`](../interfaces/SvelteKeyLockState.md)

Object with a reactive `value` property: `true` when the lock is
on, `false` when it is off, or `null`

## Example

```svelte
<script>
  import { getKeyLockState } from '@tanstack/svelte-hotkeys'

  const capsLock = getKeyLockState('CapsLock')
</script>

<label>
  Password
  <input type="password" />
  {#if capsLock.value}
    <span role="status">Caps Lock is on</span>
  {/if}
</label>
```
