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 OpenOffice.org [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.
'https://extensions.openoffice.org/en/project/alternative-dialog-find-replace-writer-altsearch
Sub setMacroShortcut(applicationOrDocument,libraryname, Modulename, subOrFunctionName,modifiers, keycode)
   dim i as long,st as string, ky as new com.sun.star.awt.KeyEvent

   objModuleCfgMgrSupplier = createUnoService("com.sun.star.ui.ModuleUIConfigurationManagerSupplier")
'   ModuleCfgMgr = objModuleCfgMgrSupplier.getUIConfigurationManager("com.sun.star.text.TextDocument")
   ModuleCfgMgr = objModuleCfgMgrSupplier.getUIConfigurationManager("com.sun.star.script.BasicIDE")
   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
   next

   ' "vnd.sun.star.script:LibName.ModuleName.SubName?language=Basic&location=application"
   st = "vnd.sun.star.script:" & libraryname &  "." & Modulename & "." & subOrFunctionName & "?language=Basic&location="  & applicationOrDocument
   ShortCutMgr.setkeyevent ky,st

End Sub


Edit:

Keycode constants and modifier constants are here:

http://www.openoffice.org/api/docs/comm ... t/Key.html

http://www.openoffice.org/api/docs/comm ... ifier.html


Example call:

setMacroShortcut "application","JeTest", "Module1","Test2", &h2,519 'Ctrl + h
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
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