I play contract bridge and want to be able to quickly insert one of the four suit symbols into a Google Docs document. The clubs and spades symbols need to be black and the diamonds and hearts symbols need to be red, like this:
Thanks in advance.
Inserting a coloured "character"
Re: Inserting a coloured "character"
Code: Select all
F2::paste("diamonds")
F3::paste("clubs")
F4::paste("spades")
F5::paste("hearts")
paste(suit) {
Clipboard := "", setClipboardBitmap(A_ScriptDir "\" suit ".png")
ClipWait, 0, WaitForAnyData := True
If ErrorLevel
MsgBox, 48, Error, An error occurred while waiting for the clipboard.
Else Send ^v
}
setClipboardBitmap(Filename) { ; By SKAN on D3AG @ tiny.cc/setclipboardbitmap
Local HBM := 0, RES := 0, OCB := 0, CF_BITMAP := 2
If ( HBM := LoadPicture(Filename) )
If ( HBM := DllCall("CopyImage", "Ptr",HBM, "Int",0, "Int",0, "Int",0, "Int",8, "Ptr") )
If ( OCB := DllCall("OpenClipboard", "Ptr",A_ScriptHwnd) )
If DllCall("EmptyClipboard")
RES := DllCall("SetClipboardData", "Int",CF_BITMAP, "Ptr",HBM)
OCB := OCB ? DllCall("CloseClipboard")*0 : 0
HBM := HBM ? DllCall("DeleteObject", "Ptr",HBM)*0 : 0
Return !!RES
}
- Attachments
-
- diamonds.png (247 Bytes) Viewed 369 times
-
- hearts.png (265 Bytes) Viewed 369 times
-
- spades.png (248 Bytes) Viewed 369 times
- flyingDman
- Posts: 2791
- Joined: 29 Sep 2013, 19:01
Re: Inserting a coloured "character"
Or you can use ascii characters for these 4. Make sure you encode your script UTF-8 with BOM:
♥ some text ⯁ some text ♣ some text ♠
Code: Select all
oWord := ComObjActive("word.application")
#!1::
oword.Selection.Font.textcolor := 0
oWord.Selection.TypeText("♠")
return
#!2::
oword.Selection.Font.textcolor := 0
oWord.Selection.TypeText("♣")
return
#!3::
oword.Selection.Font.textcolor := 255
oWord.Selection.TypeText("♦")
oword.Selection.Font.textcolor := 0
return
#!4::
oword.Selection.Font.textcolor := 255
oWord.Selection.TypeText("♥")
oword.Selection.Font.textcolor := 0
return
14.3 & 1.3.7
Re: Inserting a coloured "character"
That works great, thanks. The only difficulty is that the symbol is too large for the text. Is there a way I could programmatically resize to match the fontsize?mikeyww wrote: ↑04 Dec 2021, 17:23Code: Select all
F2::paste("diamonds") F3::paste("clubs") F4::paste("spades") F5::paste("hearts") paste(suit) { Clipboard := "", setClipboardBitmap(A_ScriptDir "\" suit ".png") ClipWait, 0, WaitForAnyData := True If ErrorLevel MsgBox, 48, Error, An error occurred while waiting for the clipboard. Else Send ^v } setClipboardBitmap(Filename) { ; By SKAN on D3AG @ tiny.cc/setclipboardbitmap Local HBM := 0, RES := 0, OCB := 0, CF_BITMAP := 2 If ( HBM := LoadPicture(Filename) ) If ( HBM := DllCall("CopyImage", "Ptr",HBM, "Int",0, "Int",0, "Int",0, "Int",8, "Ptr") ) If ( OCB := DllCall("OpenClipboard", "Ptr",A_ScriptHwnd) ) If DllCall("EmptyClipboard") RES := DllCall("SetClipboardData", "Int",CF_BITMAP, "Ptr",HBM) OCB := OCB ? DllCall("CloseClipboard")*0 : 0 HBM := HBM ? DllCall("DeleteObject", "Ptr",HBM)*0 : 0 Return !!RES }
Re: Inserting a coloured "character"
Thanks. My original post wasn't clear enough, I'm afraid. Your method works nicely from within Microsoft Word, but I'm actually trying to do this in a Google Docs environment. Can the method be modified for that?flyingDman wrote: ↑04 Dec 2021, 18:01Or you can use ascii characters for these 4. Make sure you encode your script UTF-8 with BOM:
♥ some text ⯁ some text ♣ some text ♠Code: Select all
oWord := ComObjActive("word.application") #!1:: oword.Selection.Font.textcolor := 0 oWord.Selection.TypeText("♠") return #!2:: oword.Selection.Font.textcolor := 0 oWord.Selection.TypeText("♣") return #!3:: oword.Selection.Font.textcolor := 255 oWord.Selection.TypeText("♦") oword.Selection.Font.textcolor := 0 return #!4:: oword.Selection.Font.textcolor := 255 oWord.Selection.TypeText("♥") oword.Selection.Font.textcolor := 0 return
20211204_153733.jpg
Or, even better, you came up with a method elsewhere of pressing F12 to display special characters in a popup menu (I don't know how to link to it, sorry). Could that method be modified to include a coloured character. I suspect not, because I think that method used a character set that doesn't include the suits symbols.
Re: Inserting a coloured "character"
I was just using the image that you posted. I don't know much about Google Docs or how to get the font, but you can add a resizer. The forum has some posts & scripts about resizing. Here is one that you can try. viewtopic.php?t=2505
Who is online
Users browsing this forum: Google [Bot], marypoppins_1, skeerrt and 135 guests