Missing reference for keyboard keys #2974
-
QuestionWhere's the reference for keyboard keys? There should be a complete list of possible values for KeyEventArguments passed to ui.keyboard callback. These are not provided anywhere in the ui.keyboard doc page. For instance:
If these values are taken from another reference (such as js key events), then the complete spec should be linked from the ui.keyboard docs page. Did I miss them somewhere else? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
Thanks for bringing this up, @ed2050. I just created PR #3010 to address this issue. |
Beta Was this translation helpful? Give feedback.
-
ExampleHere's an example of why having key.name values for all keys matters. Checking key.name is more flexible than checking properties. For instance, I can define a dict mapping keys to actions, and use that in keyboard listener to dispatch key events. Something like: keymappings = {
'a' : lambda : keepnames (allnames) ,
'o' : lambda : keepnames (allnames [0]) ,
'p' : lambda : prune () ,
'z' : lambda : reload_page () ,
'LeftArrow' : load_prev ,
'RightArrow' : load_next ,
}
def keylisten (evt) :
func = keymappings.get (evt.key.name, none)
if func : func ()
ui.keyboard (on_key = keylisten) This is a convenient and dynamic way to dispatch key actions without writing |
Beta Was this translation helpful? Give feedback.
-
Hi @ed2050, The implementation of keyboard event arguments is pretty straightforward and can be found here: Lines 137 to 353 in 5a25f18 It is derived from JavaScript's keyboard events which are documented here: Maybe you can take a look and let us know what specific information should be added to the documentation? As usual, we like to keep it short, but avoiding confusion by giving a few more hints can't hurt. Thanks! 🙂 |
Beta Was this translation helpful? Give feedback.
-
It would also be nice to have a shortcut to detect if any modifier keys were pressed. Detecting no mod keys is a common pattern. So instead of tedious code like this : if key == 'a' and not (key.modifiers.alt or key.modifiers.ctrl or key.modifiers.meta or key.modifiers.shift) :
do something ... We could have code like this : if key == 'a' and not any (key.modifiers) :
do something .... This would just require that key.modifiers be iterable over its if key == 'a' and not key.modifiers :
do something which would require key.modifiers to convert to boolean. (And either works with my example key dispatcher above. It's true that users could write their own function Thanks. |
Beta Was this translation helpful? Give feedback.
Thanks for bringing this up, @ed2050. I just created PR #3010 to address this issue.