This will allow you to assign a temporary shortcut to any macro.
Code: Select all
'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
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