Assign a shortcut for a macro

Creating Extension - Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This forum is not for asking questions about writing your own macros.

Assign a shortcut for a macro

Postby JeJe » Wed Mar 27, 2019 1:14 pm

OpenOffice's F5 only calls the first macro in a module.

This will allow you to assign a temporary shortcut to any macro.

Code: Select all   Expand viewCollapse view

'Written with the help of code from AltSearch extension.
Sub setMacroShortcut(applicationOrDocument,libraryname, Modulename, subOrFunctionName,modifiers, keycode)
   dim i as long,st as string, ky as new

   objModuleCfgMgrSupplier = createUnoService("")
'   ModuleCfgMgr = objModuleCfgMgrSupplier.getUIConfigurationManager("")
   ModuleCfgMgr = objModuleCfgMgrSupplier.getUIConfigurationManager("")
   ShortCutMgr = ModuleCfgMgr.getShortCutManager
   ky.keycode =keycode
   ky.modifiers = modifiers
   allevents = ModuleCfgMgr.getShortCutManager.getAllKeyEvents
   for i = 0 to ubound(allevents)
      with allevents(i)
         if .modifiers = modifiers and .keycode = keycode then          '.keyfunc
            ShortCutMgr.removeKeyEvent ky
            exit for
         end if

      end with

   ' ""
   st = "" & libraryname &  "." & Modulename & "." & subOrFunctionName & "?language=Basic&location="  & applicationOrDocument
   ShortCutMgr.setkeyevent ky,st

End Sub


Keycode constants and modifier constants are here: ... t/Key.html ... ifier.html

Example call:

setMacroShortcut "application","JeTest", "Module1","Test2", &h2,519 'Ctrl + h
Openoffice 4.1.2
Windows 8
Posts: 459
Joined: Wed Mar 09, 2016 2:40 pm

Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest