 | OO-Snippets: Managing keyboard shortcutsCommons| Keywords | keybinding, keyboard shortcut, XAcceleratorConfiguration, UIConfigurationManager |
|---|
| Language | OOBasic |
|---|
| Application | Office |
|---|
| Authors | Paolo Mantovani (initial)
|
|---|
| Supported Versions | 1.0.x 1.1.x 2.0.x |
|---|
| Supported OS | All |
|---|
| Question | How do I manage keyboard shortcuts for a given document type ?
|
|---|
| Answer | The example code is a subroutine that shows several techniques in order to manage keybindings. The purpose of the macro is to set a key binding (CTRL+T) in order to launch a macro (Standard.Module1.Main) The code checks initially if the keybinding is already used. In this case the code asks to the user if he wants to change the key and, if yes, the old keybinding is removed and replaced with the new one. Notice the syntax used for the macro URL: vnd.sun.star.script:Standard.Module1.Main?language=Basic&location=application that follows the specificatios of the new OOo scripting framework (from OOo 2.0.x) |
|---|
Sub SetUpKeyBinding
Dim oModuleCfgMgrSupplier As Object
Dim oModuleCfgMgr As Object
Dim oWriterShortCutMgr As Object
Dim sCommand As String
Dim sLocCommand As String
Dim sMsg As String
Dim iMsgResult As Integer
sCommand = "vnd.sun.star.script:Standard.Module1.Main?language=Basic&location=application"
oModuleCfgMgrSupplier = createUnoService("com.sun.star.ui.ModuleUIConfigurationManagerSupplier")
oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager("com.sun.star.text.TextDocument")
oWriterShortCutMgr = oModuleCfgMgr.getShortCutManager
Dim aKeyEvent As New com.sun.star.awt.KeyEvent
With aKeyEvent
.Modifiers = com.sun.star.awt.KeyModifier.MOD1
.KeyCode = com.sun.star.awt.Key.T
End With
On Error Resume Next
sLocCommand = oWriterShortCutMgr.getCommandByKeyEvent(aKeyEvent)
On Error GoTo 0
Select Case sLocCommand
Case = ""
oWriterShortCutMgr.setKeyEvent( aKeyEvent, sCommand )
oWriterShortCutMgr.store
Case = sCommand
Case Else
sMsg = "La combinazione di tasti ""CTRL+T"" è già usata per il comando:" & Chr(10)
sMsg = sMsg & sLocCommand & """." & Chr(10) & Chr(10)
sMsg = sMsg & "Si desidera ugualmente usare questa combinazione per lanciare Standard.Module1.Main?"
iMsgResult = MsgBox( sMsg, 1)
If iMsgResult = 1 Then
oWriterShortCutMgr.removeKeyEvent( aKeyEvent)
oWriterShortCutMgr.setKeyEvent( aKeyEvent, sCommand )
oWriterShortCutMgr.store
End If
End Select
End Sub
|
Changelog| Date | User | Modification |
|---|
| 2006-03-23 | paolomantovani | Initial version |
|