PROPOSAL: Enhance Keyboard Events
There's an amazing javascript library called HotKeys that makes it stupid easy to build keyboard shortcuts. Hyperscript does this very well, but I think that we could make it even better by borrowing a couple of easy-to-implement ideas from Hotkeys.
We wouldn't need to change our event handlers, just enhance the events with some extra data that makes it easy for both humans and machines to recognize the keyboard combination being pressed:
on keypress(key)
if key is "ctrl+s" return save() end
if key is "ctrl+f" return find() end
if key is "alt+q" return somethingElse() end
if key is "ctrl+alt+M" return anotherCombo() end -- one way of handling uppercase characters.
if key is "ctrl+alt+shift+m" return alt() end -- an alternate way of handling uppercase characters to consider.
This would really just require an extra function that looks at keyboard events, generates this string, then inserts it into the event details. Yes?
I think we should make the is expression pluggable, like with the as expression, so this could be done as an extension.
A pluggable is is an interesting idea I'd be interested in exploring further. But for this, it might be hard to implement. Perhaps this could just be a custom function like if codeFor(event) is "ctrl+s" -- this could be implemented outside of hyperscript.
Perhaps this could just be a custom function like
if codeFor(event) is "ctrl+s".
Or a custom conversion: if event as Hotkey is "Ctrl+S"
Yes. This is the best way to handle this. It should be a custom conversion.