快速建立個人常用詞庫-AutoHotkey 熱字串小工具:HotString Helper(AHK #3)
HotString Helper(熱字串助手)是一個 AutoHotkey 的熱鍵腳本程式,按一個鍵就能把選取好的文字加入自己使用的腳本裡,並且不需重載能立即生效,對於需要新增眾多熱字串的朋友們是個不可多得的簡單工具。
HotString Helper 的腳本能由 AutoHotkey 的說明網頁热字串 - 定义与使用 | AutoHotkey裡找到。
腳本程式
#h:: ; Win+H hotkey
; Get the text currently selected. The clipboard is used instead of
; "ControlGet Selected" because it works in a greater variety of editors
; (namely word processors). Save the current clipboard contents to be
; restored later. Although this handles only plain text, it seems better
; than nothing:
AutoTrim Off ; Retain any leading and trailing whitespace on the clipboard.
ClipboardOld := ClipboardAll
Clipboard := "" ; Must start off blank for detection to work.
Send ^c
ClipWait 1
if ErrorLevel ; ClipWait timed out.
return
; Replace CRLF and/or LF with `n for use in a "send-raw" hotstring:
; The same is done for any other characters that might otherwise
; be a problem in raw mode:
StringReplace, Hotstring, Clipboard, ``, ````, All ; Do this replacement first to avoid interfering with the others below.
StringReplace, Hotstring, Hotstring, `r`n, ``r, All ; Using `r works better than `n in MS Word, etc.
StringReplace, Hotstring, Hotstring, `n, ``r, All
StringReplace, Hotstring, Hotstring, %A_Tab%, ``t, All
StringReplace, Hotstring, Hotstring, `;, ```;, All
Clipboard := ClipboardOld ; Restore previous contents of clipboard.
; This will move the InputBox's caret to a more friendly position:
SetTimer, MoveCaret, 10
; Show the InputBox, providing the default hotstring:
InputBox, Hotstring, New Hotstring, Type your abreviation at the indicated insertion point. You can also edit the replacement text if you wish.`n`nExample entry: :R:btw`::by the way,,,,,,,, :R:`::%Hotstring%
if ErrorLevel ; The user pressed Cancel.
return
if InStr(Hotstring, ":R`:::")
{
MsgBox You didn't provide an abbreviation. The hotstring has not been added.
return
}
; Otherwise, add the hotstring and reload the script:
FileAppend, `n%Hotstring%, %A_ScriptFullPath% ; Put a `n at the beginning in case file lacks a blank line at its end.
Reload
Sleep 200 ; If successful, the reload will close this instance during the Sleep, so the line below will never be reached.
MsgBox, 4,, The hotstring just added appears to be improperly formatted. Would you like to open the script for editing? Note that the bad hotstring is at the bottom of the script.
IfMsgBox, Yes, Edit
return
MoveCaret:
IfWinNotActive, New Hotstring
return
; Otherwise, move the InputBox's insertion point to where the user will type the abbreviation.
Send {Home}{Right 3}
SetTimer, MoveCaret, Off
return
操作步驟
操作的步驟很簡單:
- 選取要加入腳本檔的文字
- 按[Win+h]
- 在彈出的對話窗輸入熱字串的鍵值
- 按確定
接著就能直接使用這個剛入的熱字串了。如果開啟你的腳本檔,即能發現熱字串的指令已經加進去了。
說明與示範影片
##
您可能也會有興趣的類似文章
- 提升輸入效率的文字替換工具:WriteYours與PhraseExpress (0則留言, 2020/04/11)
- AutoHotkey 熱字串的常用選項與指引功能(AHK #2) (9則留言, 2019/05/17)
- Windows虛擬桌面操作攻略;搭配強化工具更方便! [AHK#43] (0則留言, 2021/02/28)
- [Tools] 常用的AutoHotKey設定 (9則留言, 2005/05/12)
- AutoHotkey腳本的4種除錯方法(AHK #5) (0則留言, 2019/05/25)
- 輕鬆學會彈指神功-揭露AutoHotkey絕技 (63則留言, 2008/04/10)
- [AHK#52] 1.1.28新功能:Function Hotstring (0則留言, 2022/07/10)
- 用AutoGUI來學習AutoHotkey!超級簡單!(AHK #1) (0則留言, 2019/05/14)
- [Tools] 操作熱鍵與熱字串的超便利工具:AutoHotKey (13則留言, 2005/04/29)
- [AHK#53] AutoHotkey多行內容輸出時的偏移問題 (0則留言, 2022/07/31)
- 設定視窗位置與大小的小工具 WinMove-ahk [AHK#44] (0則留言, 2021/03/07)
- [AHK#54] 用AutoHotkey快速輸出Markdown標題井號(Hashes) (0則留言, 2022/08/06)
- AutoHotkey的進階剪貼簿功能:WinClip類別 (0則留言, 2019/10/26)
- [AHK#33] 重覆執行cmd.exe的「舊」命令 (0則留言, 2020/03/29)
- 支援Unicode的Autohotkey終於浮上抬面! (3則留言, 2010/10/16)
Sorry, 很久沒用Google sc…