Hotkeys Docs
Getting Started
AI/LLM: This documentation page is available in plain markdown format at/hotkeys/latest/docs/framework/svelte/reference/functions/getKeyLockState.md
getKeyLockState
ts
function getKeyLockState(key): SvelteKeyLockState;Defined in: packages/svelte-hotkeys/src/getKeyLockState.svelte.ts:54
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#
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>