Ask Your Question

[Solved] LO Basic setKeyEvent syntax, Command part

asked 2018-12-15 19:42:31 +0200

João Luís gravatar image

updated 2018-12-17 19:26:26 +0200

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 = ""
    oModuleCfgMgrSupplier = createUnoService("") 
    oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager("") 

    oWriterAccelCfgmgr = oModuleCfgMgr.getShortCutManager() 

    Dim aKeyEvent as new 
    aKeyEvent.Modifiers = 
    aKeyEvent.KeyCode   = 

    msgbox  oWriterAccelCfgmgr.getCommandByKeyEvent(aKeyEvent)
End Sub

sub MainSave

    dim document   as object
    dim dispatcher as object

    document   = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("")

    dispatcher.executeDispatch(document, ".uno:Save", "", 0, Array())
end sub
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2018-12-15 21:00:23 +0200

Ratslinger gravatar image


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?

edit flag offensive delete link more


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.

João Luís gravatar imageJoão Luís ( 2018-12-15 23:19:13 +0200 )edit

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

Ratslinger gravatar imageRatslinger ( 2018-12-16 00:24:47 +0200 )edit

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

sCommand = ""


sCommand = ""

Tested with and Draw was modified.

Ratslinger gravatar imageRatslinger ( 2018-12-16 01:17:27 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-12-15 19:42:31 +0200

Seen: 79 times

Last updated: Dec 17 '18