如何使用AutoHotkey插入格式化文本? [英] How do I insert formatted text using AutoHotkey?

查看:493
本文介绍了如何使用AutoHotkey插入格式化文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个脚本,可以在任何Windows应用程序中插入今天的日期。当我将其粘贴到目标应用程序时,我想要控制字体和/或颜色等格式。我似乎无法在文档或任何帮助论坛中找到它。

解决方案

带格式的文本可以存储在剪贴板使用AutoHotkey 1.1(又名AutoHotkey_L)和一个名为 WinClip

  #Include WinClipAPI.ahk 
#Include WinClip.ahk

;格式化当前时间。
FormatTime时间

;清除之前的剪贴板内容。
WinClip.Clear()

;在剪贴板上存储时间,使用纯文本格式,RTF格式和HTML格式。 WinClip.SetHTML(< b>时间} < / b>)

有些程式只接受特定的格式。对于不允许格式化的程序,需要纯文本,而RTF在Wordpad中工作,HTML在Word中工作。 RTF也适用于Word,但是我发现它将字体更改为Times New Roman(当HTML不存在时)。

一旦它被存储在剪贴板上, WinClip.Paste()发送^ v 将会粘贴它。


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.

解决方案

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.

这篇关于如何使用AutoHotkey插入格式化文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆