I have a template in which macros are triggered by hotkeys. I can see how to narrow hotkeys to Writer documents, but is there a way to make them only available for a specific template? Right now, if you are editing a document that is not based on my template, it gives an error message that basically tells you that the macro is not available. Maybe there is a way to activate hotkeys in a “new” or “open” event and then deactivate them when you close the document?
The hotkey assignations can not be saved into the documents. They can handle the application-scope only. Therefore you must save the assigned macros in the MyMacros.
You can use user defined Menus, Toolbars and Context menus instead of the Hotkeys. (They can be saved into a specific documents - with document-scope.)
Hello @Zizi64,
you’re right, with onboard tools it’s not possible, but find attached a .ods file, where the shortcut CTRL+ALT+H shows/hides the two buttons on the top of the sheet.
It’s described in the document, how to embedd the shortcut and bind it to a macro.
Hide_Show_Buttons_Accelerator_embedded_in_CurrentXMLods.ods (22.7 KB)
An example of assigning document-specific hotkey by macro.
For this particular document (ThisComponent), the Ctrl+A key combination will invoke the About command.
' Assigns CTRL+A keyboard document-specific shortcut to the About command.
Sub TestDocShortcut
Dim oKeyEvent As New com.sun.star.awt.KeyEvent, oDocShortCutManager
oKeyEvent.Modifiers=2 ' CTRL
oKeyEvent.KeyCode=com.sun.star.awt.Key.A
oDocShortCutManager = ThisComponent.UIConfigurationManager.ShortCutManager
oDocShortCutManager.setKeyEvent oKeyEvent, ".uno:About"
oDocShortCutManager.store ' Makes a keyboard shortcut change permanent for a document
End Sub