How do I insert formatted text using AutoHotkey?

半城伤御伤魂 提交于 2019-12-08 16:53:39

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/13222689/how-do-i-insert-formatted-text-using-autohotkey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!