Page 1 of 1

[Solved] Card Suit Symbol Shortcuts in OpenOffice For Bridge

Posted: Wed May 28, 2014 5:39 pm
by jinglenose
I'm going to explain how to create suit symbol macros in openoffice and assign them to a short cut key combination. In this case I'm going to assign them to alt-c, alt-d, alt-h and alt-s for clubs, diamonds, hearts and spades. You just need to press alt and c to get a club symbol for instance.

Go to the menu item...

Tools >> Macros >> Organise Macros >> Openoffice.orb basic and the following window should turn up...


Click edit and a text editor should appear that contain the macro code. All you need to do is move to the end and past in this code...

Code: Select all

sub Club

dim document   as object
dim dispatcher as object

document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Text"
args1(0).Value = "♣"

dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())

end sub

sub Diamond

dim document   as object
dim dispatcher as object

document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Text"
args1(0).Value = "♦"

dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())

end sub

sub Heart

dim document   as object
dim dispatcher as object

document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Text"
args1(0).Value = "♥"

dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())

end sub

sub Spade

dim document   as object
dim dispatcher as object

document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Text"
args1(0).Value = "♠"

dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())

end sub
Close the text editor and it should save the changes.

Now we need to assign these to a short cut. Choose the menu item...

Tools >> Customise

Then choose the keyboard tab. Scroll down the key combinations list box until you see the alt-c option etc.
You then choose openoffice.org macros >> user >> standard >> module and choose the appropriate function. Lets start with the "Club" function. Select alt-c in the shortcuts list and the click modify. This will then associate alt-c with the clubs function. Do this for each suit shortcut you want and then click OK.

Good luck!

Re: Creating Card Suit Symbol Shortcuts in OpenOffice For Br

Posted: Wed May 28, 2014 5:53 pm
by John_Ha
My bridge playing colleague did this by AutoCorrect, where he told AOO to AutoCorrect, say, [c] to a black ♣ (and removing the square brackets), where you have already created the ♣ (Insert > Special character ...) and you copy and paste it into the Replace field. Similarly for diamonds, hearts and clubs. If you want the number to be red/black, then AutoCorrect [6h] to a red 6♥ etc.

Re: Creating Card Suit Symbol Shortcuts in OpenOffice For Br

Posted: Wed May 28, 2014 6:31 pm
by acknak
You could also define autotexts for the suits (or cards). For example, (once you've configured it) type csh and press F3 to get the suit symbol.

Re: Creating Card Suit Symbol Shortcuts in OpenOffice For Br

Posted: Mon Jan 25, 2021 1:45 am
by dcleal
Quiet in here, but as I came here before I eventually solved the problem, here's my answer. A Python macro that does what the OP asked for (none of the other routes worked nicely for me).

Code: Select all

import uno

BLACK = 0
RED = 16711680

def insert_club():
    return insert(BLACK, '♣')

def insert_diamond():
    return insert(RED, '♦')

def insert_heart():
    return insert(RED, '♥')

def insert_spade():
    return insert(BLACK, '♠')

def insert(textColor, text):
    model = XSCRIPTCONTEXT.getDesktop().getCurrentComponent()
    cursor = model.CurrentController.ViewCursor
    oldColor = cursor.getPropertyValue('CharColor')
    cursor.setPropertyValue('CharColor', textColor)
    model.getText().insertString(cursor, text, False)
    cursor.setPropertyValue('CharColor', oldColor)
    return None

Re: Creating Card Suit Symbol Shortcuts in OpenOffice For Br

Posted: Mon Jan 25, 2021 1:55 pm
by John_Ha
AutoHotKey does it too and in any application.

Re: [Solved] Card Suit Symbol Shortcuts in OpenOffice For Br

Posted: Mon Jan 25, 2021 11:56 pm
by robleyd
Not any application - any application running under Windows only.

Re: [Solved] Card Suit Symbol Shortcuts in OpenOffice For Br

Posted: Tue Jan 26, 2021 1:19 am
by John_Ha
Good point! The penalty of hijacking a thread - the OP used W7.

I wonder what happens running it under WINE?

I use AutoHotKey for lots of things - it's magic.

Re: [Solved] Card Suit Symbol Shortcuts in OpenOffice For Br

Posted: Tue Jan 26, 2021 1:34 am
by robleyd
AutoKey is probably the nearest thing available for *nix; and Apple provide an application named Automator that is vaguely similar.