Skip to content

Listen for some hotkeys on form fields #85

Answered by keithamus
SethHorsley asked this question in Q&A
Discussion options

You must be logged in to vote

In cases where we need a global shortcut that will work in all inputs, we use manual event listeners. The code might look a bit like:

import {eventToHotkeyString} from '@github/hotkey'
const GLOBAL_HOTKEY = 'Cmd+K'

document.addEventListener('keydown', (event) => {
  let hotkeyString = eventToHotkeyString(event)
  if (!hotkeyString) return
  if (hotkeyString !== GLOBAL_HOTKEY) return

  runGlobalHotkeyCommand()
})

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by keithamus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #83 on March 06, 2023 11:13.