Set Keyboard shortcuts for extensions

I wrote an extension for LibreOffice. I would like to trigger some functions via a keyboard shortcut. However, I was unable to find out how this can be done. I saw that some extension have macros that – by standard – can be assigned to shortcuts, but I did not find out 1) yet how I could trigger functions of my extension via a macro 2) How I can integrate the macros in my extension. (see below – implementation uses uno service, not macros)

Mentioned extension: https://extensions.libreoffice.org/extensions/qda-tagtree
The “update” function should be trigger-able with a keyboard shortcut.

UPDATE:

Turned out that this is a bit more complicated. So the "Accelerators.xcu" part worked (it shows up in the Keyboard-shortcut customization dialog).

However, using the shortcut does not work. I found out that executing a method on the triggering of a shortcut need a UNOService to call.

I created the service and implemented an XJobExecutor Interface. Pressing the assigned Shortcut, Ctrl+Shift+L does not result in execution of the trigger method.

I wonder what goes wrong, but even if I debug the code step by step I can’t find out where it goes wrong. I was sadly unable to find a documentation of the .addImplementation method of g_ImplementationHelper which might help me.

hello @d_jan,
this is beyond my expertise, but one thing you could try and see if it helps is changing the updateTrigger into triggerUpdateJob :

g_ImplementationHelper.addImplementation( triggerUpdateJob, "tagtree.qdaaddon.de.fordes.qdatreeappfunctions", ("com.sun.star.task.Job",),)

Hello @d_jan,

tho i never did this myself, it seems to me that you could just add an "Accelerators.xcu" to your extension, with a node defining a shortcut key to your Update function.

e.g. for CTRL+U:

  <node oor:name="PrimaryKeys">
    <node oor:name="Global">
	...
	...
      <node oor:name="U_MOD1" oor:op="replace">
        <prop oor:name="Command">
          <value xml:lang="en-US">vnd.sun.star.script:Library.Module.Update?language=Python&amp;location=application</value>
        </prop>
      </node>
	...
	...

The macro URI must be changed to point to your Update function.

Please see Framework / Article / Accelerators Configuration

Hope this helps, lib

1 Like

Thanks, lib, I’ll give that a try!