Ask Your Question
0

[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 = "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 

    setKeyEvent(aKeyEvent,sCommand)
    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
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

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

Ratslinger gravatar image

Hello,

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

setKeyEvent(aKeyEvent,sCommand)

to:

oWriterAccelCfgmgr.setKeyEvent(aKeyEvent,sCommand)

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

Comments

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 = "vnd.sun.star.script:Standard.Module2.MainSave?language=Basic&location=document"

to:

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

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

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

Question Tools

1 follower

Stats

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

Seen: 39 times

Last updated: Dec 17 '18