JSFiddle - React, Tailwind, and code Playground

by joplomacedo

JavaScript

const map = {}

document.addEventListener('keydown', e => {
  const slug = `${ e.shiftKey ? '⇧-' : '' }${ e.ctrlKey ? '⌥-' : '' }${ e.metaKey ? '⌘-' : '' }${e.key}`
  map[slug] = map[slug] || []
  map[slug].forEach(clearTimeout)
  map[slug].push(setTimeout(() => delete map[slug], 300))
  if (map[slug].length === 2) {
    console.log(`Double keypress of ${slug}`)
  }
})