Skip to main content
Vuetify0 is now in alpha!
Vuetify0 Logo
Theme
Mode
Palettes
Accessibility
Vuetify One
Sign in to Vuetify One

Access premium tools across the Vuetify ecosystem — Bin, Play, Studio, and more.

Not a subscriber? See what's included

useHotkey

A composable for handling hotkey combinations and sequences with platform-aware modifiers and automatic cleanup.


IntermediateApr 5, 2026

Usage

The useHotkey composable registers hotkey handlers on the window with automatic cleanup when the component is unmounted. It supports key combinations (ctrl+k), key sequences (g-h), and platform-aware modifier mapping.

vue
<script setup lang="ts">
  import { useHotkey } from '@vuetify/v0'
  import { ref } from 'vue'

  const commandPaletteOpen = ref(false)
  const message = ref('')

  // Simple key combination - Ctrl+K (Cmd+K on Mac)
  useHotkey('ctrl+k', () => {
    commandPaletteOpen.value = true
  })

  // Key sequence (GitHub-style) - press 'g' then 'h'
  useHotkey('g-h', () => {
    message.value = 'Go home!'
  })

  // With multiple modifiers
  useHotkey('ctrl+shift+s', () => {
    message.value = 'Save all!'
  })

  // Allow in inputs with the inputs option
  useHotkey('escape', () => {
    commandPaletteOpen.value = false
  }, { inputs: true })
</script>

<template>
  <div>
    <p>Press Ctrl+K to open command palette</p>
    <p>Press g then h for GitHub-style navigation</p>
    <p v-if="message">{{ message }}</p>
  </div>
</template>

Key Aliases

Key strings are normalized before matching, so you can use human-friendly names instead of exact KeyboardEvent.key values:

AliasCanonical
escescape
returnenter
deldelete
space, spacebar (space character)
up / down / left / rightarrowup / arrowdown / arrowleft / arrowright
controlctrl
commandcmd
optionalt
plus+
minus, hyphen-
slash/
underscore_
ts
// These are equivalent:
useHotkey('escape', close)
useHotkey('esc', close)

useHotkey('ctrl+plus', zoomIn)   // matches Ctrl ++
useHotkey('cmd+minus', zoomOut)  // matches Cmd +-

Architecture

useHotkey builds on useEventListener for keyboard event handling:

Hotkey Hierarchy

Use controls to zoom and pan. Click outside or press Escape to close.

Hotkey Hierarchy

Reactivity

Property/MethodReactiveNotes
isActiveComputed from cleanup ref
isPausedShallowRef, readonly
keysAccepts MaybeRefOrGetter, watched for changes

Examples

Command Palette

A searchable command palette (Cmd+J) with arrow-key navigation, filtered results, and per-command shortcuts.

ESC
navigate selectesc close

API Reference

The following API details are for the useHotkey composable.

Functions

useHotkey

(keys: MaybeRefOrGetter<string | undefined>, callback: (e: KeyboardEvent) => void, options?: UseHotkeyOptions, _platform?: PlatformContext | undefined) => UseHotkeyReturn

A composable that listens for hotkey combinations and sequences.

Options

event

MaybeRefOrGetter<"keydown" | "keyup"> | undefined

The keyboard event type to listen for.

Default: 'keydown'

inputs

MaybeRefOrGetter<boolean> | undefined

Whether to trigger the callback when an input element is focused.

Default: false

preventDefault

MaybeRefOrGetter<boolean> | undefined

Whether to prevent the default browser action.

Default: true

stopPropagation

MaybeRefOrGetter<boolean> | undefined

Whether to stop event propagation.

Default: false

sequenceTimeout

MaybeRefOrGetter<number> | undefined

Timeout in ms before a key sequence resets.

Default: 1000

Properties

isActive

Readonly<Ref<boolean, boolean>>

Whether the hotkey listener is currently active (listening for keys). False when paused, when keys is undefined, or in SSR.

isPaused

Readonly<Ref<boolean, boolean>>

Whether the hotkey listener is currently paused.

Methods

pause

() => void

Pause listening (removes listener but keeps configuration).

resume

() => void

Resume listening after pause.

stop

() => void

Stop listening and clean up (removes listener).

Was this page helpful?

© 2016-1970 Vuetify, LLC
Ctrl+/