leva
leva copied to clipboard
Hotkeys / keyboard shortcuts for boolean values
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 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])