von Steffan » Do, 07.09.2006 09:00
Hallo zusammen,
ich hab das Problem inzwischen durch einen Codebeispiel (
http://codesnippets.services.openoffice ... tcuts.snip), dass ich angepasst habe, lösen können und poste hier die Lösung für alle die es interessiert:
In meinem Beispiel wird bei Aktivierung des Dokuments der Taste 'A' das Makro 'showAddressinfo1' zugewiesen. Bei Deaktivierung des Dokument wird diese Zuweisung gelöscht
Code: Alles auswählen
Sub onActivate
sMacro = "vnd.sun.star.script:Standard.info.showAddressinfo1?language=Basic&location=document"
call setShortCut(512, 0, sMacro)
End Sub
Sub onDeactivate
call setShortCut(512, 0, "")
End Sub
Sub setShortCut(lKey as long, iMod as integer, sFunction as String)
'Ändert Shortcuts für Tasten bzw. Tastenkombinationen
'alte Shortcut werden ohne Rückfrage überschrieben!
' lKey ... die Taste (Keykonstanten unter http://api.openoffice.org/docs/common/ref/com/sun/star/awt/Key.html)
' iMod ... Zusatztaste (Shift = 1, Ctrl = 2, Alt =4)
' sFunction ... Makro, das ausgeführt werden soll
' Short-Cut-Manager holen
oModuleCfgMgrSupplier = createUnoService("com.sun.star.ui.ModuleUIConfigurationManagerSupplier")
oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager("com.sun.star.text.TextDocument")
oWriterShortCutMgr = oModuleCfgMgr.getShortCutManager
' Werte definieren
Dim aKeyEvent As New com.sun.star.awt.KeyEvent
aKeyEvent.KeyCode = lKey
aKeyEvent.Modifiers = iMod
' vorhandene Belegung auslesen
On Error Resume Next
sLocCommand = oWriterShortCutMgr.getCommandByKeyEvent(aKeyEvent)
On Error GoTo 0
' neue Belegung zuweisen
Select Case sLocCommand
Case = "" 'Shortcut ist nicht belegt
oWriterShortCutMgr.setKeyEvent( aKeyEvent, sFunctiom )
oWriterShortCutMgr.store
Case = sFunction 'Shortcut ist schon mit richtiger Funktion belegt
Case Else 'Shortcut mit anderer Funktion belegt
oWriterShortCutMgr.removeKeyEvent( aKeyEvent)
if sFunction <>"" then oWriterShortCutMgr.setKeyEvent( aKeyEvent, sFunction )
oWriterShortCutMgr.store
End Select
End Sub
Steffan
Hallo zusammen,
ich hab das Problem inzwischen durch einen Codebeispiel ([url]http://codesnippets.services.openoffice.org/Office/Office.ManagingKeyboardShortcuts.snip[/url]), dass ich angepasst habe, lösen können und poste hier die Lösung für alle die es interessiert:
In meinem Beispiel wird bei Aktivierung des Dokuments der Taste 'A' das Makro 'showAddressinfo1' zugewiesen. Bei Deaktivierung des Dokument wird diese Zuweisung gelöscht
[code]Sub onActivate
sMacro = "vnd.sun.star.script:Standard.info.showAddressinfo1?language=Basic&location=document"
call setShortCut(512, 0, sMacro)
End Sub
Sub onDeactivate
call setShortCut(512, 0, "")
End Sub
Sub setShortCut(lKey as long, iMod as integer, sFunction as String)
'Ändert Shortcuts für Tasten bzw. Tastenkombinationen
'alte Shortcut werden ohne Rückfrage überschrieben!
' lKey ... die Taste (Keykonstanten unter http://api.openoffice.org/docs/common/ref/com/sun/star/awt/Key.html)
' iMod ... Zusatztaste (Shift = 1, Ctrl = 2, Alt =4)
' sFunction ... Makro, das ausgeführt werden soll
' Short-Cut-Manager holen
oModuleCfgMgrSupplier = createUnoService("com.sun.star.ui.ModuleUIConfigurationManagerSupplier")
oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager("com.sun.star.text.TextDocument")
oWriterShortCutMgr = oModuleCfgMgr.getShortCutManager
' Werte definieren
Dim aKeyEvent As New com.sun.star.awt.KeyEvent
aKeyEvent.KeyCode = lKey
aKeyEvent.Modifiers = iMod
' vorhandene Belegung auslesen
On Error Resume Next
sLocCommand = oWriterShortCutMgr.getCommandByKeyEvent(aKeyEvent)
On Error GoTo 0
' neue Belegung zuweisen
Select Case sLocCommand
Case = "" 'Shortcut ist nicht belegt
oWriterShortCutMgr.setKeyEvent( aKeyEvent, sFunctiom )
oWriterShortCutMgr.store
Case = sFunction 'Shortcut ist schon mit richtiger Funktion belegt
Case Else 'Shortcut mit anderer Funktion belegt
oWriterShortCutMgr.removeKeyEvent( aKeyEvent)
if sFunction <>"" then oWriterShortCutMgr.setKeyEvent( aKeyEvent, sFunction )
oWriterShortCutMgr.store
End Select
End Sub[/code]
Steffan