Simple Keyboard Macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
papafox
Posts: 6
Joined: Thu Feb 28, 2008 12:00 am

Simple Keyboard Macro

Post by papafox »

I wish to create a simple macro in writer for a key combination which is not supported by "customize keyboard". My goal is to move the cursor down one line by using the combination of the "Control" and "," keys. I know I can create the simple macro, but can I assign it to this key combination, and how do I do that?
Thx!
User avatar
Villeroy
Volunteer
Posts: 31264
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Simple Keyboard Macro

Post by Villeroy »

The old forum is the best source of OOo code snippets:
http://www.oooforum.org/forum/viewtopic ... t=shortcut

referring to this interface:
http://api.openoffice.org/docs/common/r ... etKeyEvent
and these constant groups:
http://api.openoffice.org/docs/common/r ... t/Key.html
http://api.openoffice.org/docs/common/r ... ifier.html
 Edit: Since "simple macros" are impossible with this API 

Code: Select all

Sub SetCtrlComma()
'Thanks to Carsten Driesner, Frank Sch�nheit, Paolo and ms777
Dim aKeyEvent As New com.sun.star.awt.KeyEvent
	sCommandURL = "vnd.sun.star.script:Standard.test_.CROAK?language=Basic&location=application"
	oDocCfgMgr = ThisComponent.getUIConfigurationManager()
	oShortCutManager = oDocCfgMgr.GetShortCutManager()
	With aKeyEvent
		.Modifiers = com.sun.star.awt.KeyModifier.MOD1
		.KeyCode = com.sun.star.awt.Key.COMMA
	End With
	oShortCutManager.setKeyEvent(aKeyEvent, sCommandURL)
	oDocCfgMgr.store()
End Sub
Sub CROAK
	Msgbox "BINGO"
End Sub
Pattern of sCommandURL:
vnd.sun.star.script:Library.Module.Routine?language=Basic&location=[application|document]
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
kingfisher
Volunteer
Posts: 2123
Joined: Tue Nov 20, 2007 10:53 am

Re: Simple Keyboard Macro

Post by kingfisher »

On my version, it is not possible to assign CTRL + , It's a case of using the listed key bindings. You can probably move the cell pointer down just by using the down-arrow key.
Apache OpenOffice 4.1.9 on Linux
User avatar
Bhikkhu Pesala
Posts: 1253
Joined: Mon Oct 08, 2007 1:27 am

Re: Simple Keyboard Macro

Post by Bhikkhu Pesala »

Try the free utility AutoHotkey
Idiot Compassion
LibreOffice 6.0.4 on Windows 10
User avatar
probe1
Volunteer
Posts: 277
Joined: Mon Oct 08, 2007 1:34 am
Location: Chonburi Thailand

Re: Simple Keyboard Macro

Post by probe1 »

Bhikkhu - kingfisher uses Linux ...
Cheers
Winfried

DateTime2 extension: insert date, time or timestamp, formatted to your needs
User avatar
Bhikkhu Pesala
Posts: 1253
Joined: Mon Oct 08, 2007 1:27 am

Re: Simple Keyboard Macro

Post by Bhikkhu Pesala »

Kingfisher is not asking the question, and the OP hasn't told us what OS he/she is using.
Idiot Compassion
LibreOffice 6.0.4 on Windows 10
User avatar
kingfisher
Volunteer
Posts: 2123
Joined: Tue Nov 20, 2007 10:53 am

Re: Simple Keyboard Macro

Post by kingfisher »

On further reflection, I think papafox wants a listener which will respond to CTRL + comma
Apache OpenOffice 4.1.9 on Linux
User avatar
Villeroy
Volunteer
Posts: 31264
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Simple Keyboard Macro

Post by Villeroy »

kingfisher wrote:On further reflection, I think papafox wants a listener which will respond to CTRL + comma
This is what my macro does. When you run it against the current document Ctrl+, raises a message box "BINGO".
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
papafox
Posts: 6
Joined: Thu Feb 28, 2008 12:00 am

Re: Simple Keyboard Macro

Post by papafox »

Thanks for the quick responses!
I'm using Windows Vista 32 and need to create a keyboard shortcut so that when using writer the cursor moves down one line when I hit the Ctrl and "," keys. I have used this macro before in other programs and find it quicker than using a mouse to move the cursor in most instances. Although I'm not a programmer I am capable of using logic and will study your various responses to see if one suits my needs.
papafox
Posts: 6
Joined: Thu Feb 28, 2008 12:00 am

Re: Simple Keyboard Macro

Post by papafox »

I've tried the AutoHotKey program as Bhikkhu Pesala suggested, and was able to construct a script that produces no error messages, but when I hit the "Ctrl" and the "," keys, Writer and another word processor I use respond as if I've hit the "Ctrl" and the "down arrow" keys together, rather than just the down arrow key. So, I'm still looking for a more elegant solution. Thanks all for efforts so far.
My AutoHotKey script:

Ctrl & ,::
SetKeyDelay -1
Send {Blind}{Down DownTemp}
return

Ctrl & , up::
SetKeyDelay -1
Send {Blind}{Down Up}
return
Post Reply