Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This is my first post. Feel free to provide feedback if need be.

TL/DR: Create macros. Assign key bindings.

Here's a work-around that accomplishes the goal of zooming in and out with the keyboard. The only catch is that not only are the built in "Zoom In" and "Zoom Out" commands broken, but it appears the "Ctrl + -" and "Ctrl + +" key bindings are broken as well (I couldn't assign any command to those key bindings successfully). I ended up choosing to use "Ctrl + 9" for zooming out and "Ctrl + 0" for zooming in as those key bindings felt as close to the key bindings I was going for as I could get. Here's what to do:

First, add the macros. Here are the two I created:

Sub ZoomIn

Dim doc As Object
Dim new_zoom_value As Integer
Dim dispatcher As Object

doc = ThisComponent.CurrentController.Frame
new_zoom_value = ThisComponent.CurrentController.viewSettings.ZoomValue + 5
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(2) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Zoom.Value"
args1(0).Value = new_zoom_value
args1(1).Name = "Zoom.ValueSet"
args1(1).Value = 28703
args1(2).Name = "Zoom.Type"
args1(2).Value = 0

dispatcher.executeDispatch(doc, ".uno:Zoom", "", 0, args1())

End Sub



Sub ZoomOut

Dim doc As Object
Dim new_zoom_value As Integer
Dim dispatcher As Object

doc = ThisComponent.CurrentController.Frame
new_zoom_value = ThisComponent.CurrentController.viewSettings.ZoomValue - 5
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(2) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Zoom.Value"
args1(0).Value = new_zoom_value
args1(1).Name = "Zoom.ValueSet"
args1(1).Value = 28703
args1(2).Name = "Zoom.Type"
args1(2).Value = 0

dispatcher.executeDispatch(doc, ".uno:Zoom", "", 0, args1())

End Sub

In short, the macros grab the current zoom value as a percentage, add or subtract 5 percentage points, then assign the new zoom value. You can alter the percentage that the macros zoom in or out by, by altering the number at the end of the "new_zoom_value" line.

To add the macros open the IDE (Tools -> Macros -> Edit Macros) and past the above code into "Module1": image description

Next, to assign the key bindings:

  1. Open the the "Customize" dialogue box (Tools -> Customize...)
  2. Make sure the "Keyboard" tab at the top of the dialogue box is selected
  3. Select the desired key binding from the "Shortcut Keys" menu. You may have to delete the existing key binding if you're replacing a key binding that already exist. The "Delete" key is on the right. Be aware of any key bindings that you are modifying but don't stress too much as any changes are completely reversible.
  4. Find the first macro you wish to assign a key binding to by selecting "Module1". It's near the bottom of the "Category" menu in the bottom-left quadrant of the dialogue box. You have to open up "LibreOffice Macros" and drill down to "Module1" (see pic below).
  5. Select the macro you want to assign to the chosen key binding and click "Modify" in the upper-right of the dialogue box.
  6. If the desired key binding is displayed in the "Keys" box in the bottom-right quadrant then repeat steps 3 through 5 for the other macro. Finally, click "OK" and go test it out.

Here's what it looks like AFTER clicking "Modify" but before clicking "OK": image description

Note that if you go back and look at the custom key bindings in the dialogue box, the macros will show up as a line of OpenOffice.org Basic code rather than the names you assigned them but they still work just the same.

I hope this helps!