Trigger plugin by keyboard shortcut?

Is it possible to have a plugin execute code when a keyboard shortcut is pressed (as opposed to a slash command)? I’ve looked through the API and can’t seem to find a way to listen to keyboard events. More info on my proposed use case below.

I’m trying to create “hint” style keyboard navigation, where you press a shortcut, text hints are displayed on each block, and the text you press next focuses that block. I’m able to display the hints, and, using a hidden input element, to listen to subsequent keydown events to know which hint was typed. What I’ve been unable to figure out is how to enter “hint mode” with a keyboard shortcut, as opposed to having a UI element the user clicks, or a slash command the user enters. Is there a way to do this? If not, it would be great to let plugins register keyboard shortcuts logseq would then listen to, and call the plugin code when they were pressed.

Hi, I have met the same question as you. I was wondering to develop a autocomplete plugin for latex or other types of fast typing. However, could not find a way to listen to the key.

Similarly, I’d love to hook into the paste event, to make pasting from Google Docs better. But since we can’t access the main document, we can’t hook into event listeners. Having an API for adding event listeners would be so wonderful.

I am a novice trying to figure out the same thing. Both of these plugins implement custom keyboard shortcuts, so you should be able to learn from looking at their code (that is what I am going to try, haven’t done it yet):

1 Like

Thanks–looks like registerCommandShortcut was added since I originally posted to allow this.

1 Like

How can I use it? Can someone give me an example of how to assign a keyboard shortcut to a plugin?