leva icon indicating copy to clipboard operation
leva copied to clipboard

Hotkeys / keyboard shortcuts for boolean values

Open mordv opened this issue 4 years ago • 1 comments

I think it would be nice to have an optional keyboard shortcut for boolean values out of the box. For example:

    wireframe: {
      value: false,
      shortcut: 'KeyW'
    }

Or an array for multiple keys:

    wireframe: {
      value: false,
      shortcut: ['ShiftLeft', 'KeyW']
    }

mordv avatar Apr 23 '21 17:04 mordv

@mordv I can see this being valuable, but it might be a bit tough and cumbersome to implement, taking into account a lot of potential edge cases. This could be done easily in userland, and would allow for more complex logic.

const [values, set] = useControls(() => ({ bool: true }))

useEffect(() => {
  const handler = event => {
    if(event.key === 'W') set({ bool: false })
  }
  window.addEventListener('keydown', handler)
  return () => window.removeEventListener('keydown', handler)
}, [set])

dbismut avatar Apr 26 '21 14:04 dbismut