1. Hooks
  2. useGlobalKeyDown

useGlobalKeyDown()

A utility to quickly setup hotkeys and such.
import {useGlobalKeyDown} from '@sanity/ui'
import isHotkey from 'is-hotkey'
import React, {useCallback} from 'react'

const isSaveHotkey = isHotkey('mod+s')

function App () {
  const handleGlobalKeyDown = useCallback(
    (event: KeyboardEvent) => {
      if (isSaveHotkey(event)) {
        event.preventDefault()
        // Sanity autosaves your work!
      }
    },
    []
  )
  
  useGlobalKeyDown(handleGlobalKeyDown)
  
  return <>...</>
}

Type  

(
  callback: (event: KeyboardEvent) => void;
) => void
Made withby folks at