Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I insert formatted text using AutoHotkey?

I created a script that inserts today's date in any Windows application. I would like to control the format such as font and/or color when I paste it into the target application. I can't seem to find it in the documentation or in any of the help forums.

like image 814
Joe Avatar asked Nov 04 '12 20:11

Joe


1 Answers

Formatted text can be stored in the clipboard using AutoHotkey 1.1 (a.k.a. AutoHotkey_L) and a script called WinClip:

#Include WinClipAPI.ahk
#Include WinClip.ahk

; Format the current time.
FormatTime time

; Clear previous clipboard contents.
WinClip.Clear()

; Store time on clipboard, in plain text, RTF and HTML formats.
WinClip.SetText(time)
WinClip.SetRTF("{\rtf{\b " time "}}")
WinClip.SetHTML("<b>" time "</b>")

Some programs will only accept specific formats. Plain text is needed for programs which don't allow formatting, while RTF works in Wordpad and HTML works in Word. RTF also works in Word, but I found that it changed the font to Times New Roman (when HTML wasn't present).

Once it is stored on the clipboard, WinClip.Paste() or Send ^v will paste it.

like image 119
Lexikos Avatar answered Oct 17 '22 02:10

Lexikos