[Solved] LO Basic setKeyEvent syntax, Command part

Hello Everyone,
I’ve read here about a method that used a string sCommand to reach to a module, probably got with record macro button. Then I wrote the macro below, trying to assign the Save Command to Ctrl+S. After runnig the macro, I got an error “BASIC runtime error. Sub-procedure or function procedure not defined.”, the setKeyEvent highlighted. Any Ideas?

Sub SaveKeyWriter
    sCommand = "vnd.sun.star.script:Standard.Module2.MainSave?language=Basic&location=document"
    oModuleCfgMgrSupplier = createUnoService("com.sun.star.ui.ModuleUIConfigurationManagerSupplier") 
    oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager("com.sun.star.text.TextDocument") 

    oWriterAccelCfgmgr = oModuleCfgMgr.getShortCutManager() 
    Dim aKeyEvent as new com.sun.star.awt.KeyEvent 
    aKeyEvent.Modifiers = com.sun.star.awt.KeyModifier.MOD1 
    aKeyEvent.KeyCode   = com.sun.star.awt.Key.S 
	msgbox	oWriterAccelCfgmgr.getCommandByKeyEvent(aKeyEvent)
End Sub

sub MainSave
	dim document   as object
	dim dispatcher as object
	document   = ThisComponent.CurrentController.Frame
	dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
	dispatcher.executeDispatch(document, ".uno:Save", "", 0, Array())
end sub


setKeyEvent is a function of the shortcut manager. Change this line:




Also see this post for a more complete macro → How can I write a macro to assign a shortcut to another macro?

Yes!!! Doing that nailed it! Thanks! Also, do you know how to modify the HotKeys’ list (tools->customize->keyboard->(*LibreOffice/*Writer)), not just for the Writer, but for all LibreOffice, using macros? I’d like to avoid conflicts between the two lists, accessing presentation.presentationdocument, drawing.drawingdocument, etc (elements of frame.ModuleManager), doesn’t change it.

Don’t have that info currently. If I find it will post.

@JoãoLuís One item of note regarding elements of module manager, Your macro should be stored under My Macros ->Standard and change this line:

sCommand = "vnd.sun.star.script:Standard.Module2.MainSave?language=Basic&location=document"


sCommand = "vnd.sun.star.script:Standard.Module2.MainSave?language=Basic&location=application"

Tested with com.sun.star.drawing.DrawingDocument and Draw was modified.