Replies: 4 comments 1 reply
-
I'm looking into using client-side JavaScript libraries to handle keyboard events. ctrl-keys looks like a good option. The inherent difficulty here is that the core of the event handler lives lisp-side, whereas the event is triggered js-side. So, if we wanted to call a specific handler and prevent default behavior only when the '/' key is pressed, that would require halting execution, initiating the handler on the lisp side, and waiting for the handler to return with some value that could be used to call I really just want to fire off a message from the js-side that says "Hey CLOG, this is View speaking, call [function] please." I don't really need lisp-side to know what keys were pressed, just what function/closure to call. This can probably be achieved by setting up key event handlers using ctrl-keys, calling |
Beta Was this translation helpful? Give feedback.
-
Here is my attempt at implementing hotkeys:
I didn't end up using ctrl-keys as I found basic JavaScript/JQuery was all I needed to use. Also, CLOG already has a mechanism for defining custom event handlers, so I just used that to trigger functions from the view/client. Here is an example:
You can specify conditions for each set of hotkey definitions. In the above example the condition is I have not tested this very much beyond cleaning up the few bugs that presented themselves as I wrote it. I don't currently know if this will leave lots of objects lying around uncollected when the DOM changes. (orphan hotkey handlers, etc.). |
Beta Was this translation helpful? Give feedback.
-
This is very awesome. Thanks for posting, I will use this to learn on my next project. Greatly appreciate the code samples. |
Beta Was this translation helpful? Give feedback.
-
I made a small CLOG plugin that expands a little on my previous attempt: clog-tinykeys. It uses tinykeys this time, so now it supports key combinations and sequences. |
Beta Was this translation helpful? Give feedback.
-
How is everyone implementing global keyboard shortcuts? I Have tried the basic approach of setting a keypress handler on the document object, and preventing default behavior (as I want to set a handler for the '/' key), but while the handler gets fired, it swallows every single keyboard event. For instance you can't type into form elements etc, even when they have focus. In JavaScript you have more granular control over event propagation and default behavior, as inside handlers you can specify if the event should prevent default behavior or stop propagating under specific circumstances, or keep going. Unless I have missed something CLOG only lets us specify whether default behavior should be allowed when the event is fired as a whole.
Beta Was this translation helpful? Give feedback.
All reactions