Ask Your Question

How to add Shortcut Key Combinations to Keyboard Customization [closed]

asked 2017-09-24 19:59:23 +0100

chiropterist gravatar image

I want to assign "Ctrl+-" and "Alt+-" to macros that insert an en-dash and an em-dash, respectively, in all LO modules.

By default "Ctrl+-" is assigned in Writer to insert a soft hyphen and in Calc to delete cells, but as I rarely use these functions, I'm fine with reassigning the key combinations.

The problem is that "Alt+-" doesn't appear in the list of Shortcut Keys; same for "Alt+Shift+-", "Ctrl+Shift+-", and Ctrl+Alt+Shift+-". Why? Can I add them? How?

[A similar question was asked, but not answered, at]

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-10-16 11:27:18.145188

1 Answer

Sort by » oldest newest most voted

answered 2017-09-26 14:53:10 +0100

librebel gravatar image

Hello @chiropterist,

+1 For nice question :)

Some points on beforehand:

  1. Certain Key combinations such as "ALT+-" are not listed among the available Shortcut Keys in "Tools : Customize... : Keyboard", but can still be assigned to a command by using the API. Doing so is of course at ones own responsibility, since these Key combinations were probably left out of the GUI for a reason... Even after assigning a command to such Key combinations by API, they are still not visible in the GUI; but they are truly active and they do trigger the assigned command. Such 'hidden' Shortcut Keys can only be removed again by using the API.

  2. For Key combinations such as "CTRL+-" that are already defined at the Module-level ( i.e. Writer, Calc ) like you mentioned, it would not be sufficient to install a Shortcut at the Global level for them, since they would be overruled by the Module''s Shortcut every time. Instead the Module''s Shortcut must be overwritten for each Office Module separately. Seeing that you already agreed to that in your question, i wrote a macro here below that does just that.

  3. I have tested the macro below, and it works wonderfully in Writer, Calc, Draw, Impress, Formula Editor, the BasicIDE, but with one notable exception: it doesn''t seem to do anything in LibreOffice Base. I haven''t looked into that yet, but i guess it could be solved by adjusting the method type_A_Character() to address the case for Base especially.

To try this macro, just copy-paste the code below into a Basic module inside your [My Macros and Dialogs].Standard library, then adjust the 2 constants in the method installMyShortcuts() to point to that location, then Run the method installMyShortcuts().

Hope it helps, lib

Sub installMyShortcuts()
REM Assigns 2 Keyboard shortcuts "Ctrl+-" and "Alt+-", to 2 macros that insert an en-dash and an em-dash respectively.
REM Call this method once to install the 2 Keyboard shortcuts in every Office Module.
REM To remove these 2 Keyboard shortcuts again, set the below constant bInstall to <False>, then call this method once.
REM See:

REM ******************************************************************************************************************

    Const bInstall As Boolean = True        REM True = install the 2 shortcuts; False = remove the 2 shortcuts again.

REM *******  NB  ********     Set here the correct URL of your macro to be called when ALT-Minus is pressed:
    Const strCommandURL1$   = ""

REM *******  NB  ********     Set here the correct URL of your macro to be called when CTRL-Minus is pressed:
    Const strCommandURL2$   = ""

REM ******************************************************************************************************************

On Local Error Resume Next

    Dim oKeyEvent1 As New                     REM KeyEvent representing ALT-Minus.
    oKeyEvent1.Modifiers    =
    oKeyEvent1.KeyCode      =

    Dim oKeyEvent2 As New                     REM KeyEvent representing CTRL-Minus.
    oKeyEvent2.Modifiers    =
    oKeyEvent2.KeyCode      =

    Dim oShortcutManager As ...
edit flag offensive delete link more

Question Tools



Asked: 2017-09-24 19:59:23 +0100

Seen: 1,317 times

Last updated: Sep 26 '17