次のような AHK スクリプトを書くと:
::abc::alphabet
うまく機能します。唯一の問題は、テキストのコピー部分 (自動置換したい内容を含むもの) が必要な場合、置換が行われないことです。
例えば:
!INS::{Ctrl Down}c{Ctrl Up}{Tab 2}{Enter}{Ctrl Down}v{Ctrl Up}
コピーはできますabc
が、貼り付けると、alphabet
(前に定義したように) 取得されません。
コピーして貼り付けた単語を置き換える方法はありますか?send
コマンドを使用して、自動置き換えしたい単語を含む行や単語を送信する場合などですか?
答え1
ホットストリング実際に入力した内容にのみ影響します。クリップボードあなたは正規表現置換指示。
以下は、選択したテキストをコピーし、変更した内容を貼り付けるスクリプトです (検索と置換の後)。これがあなたが言いたいことだと思います:
#x:: ;[Win]+[X]
;Empty the Clipboard.
Clipboard =
;Copy the select text to the Clipboard.
SendInput, ^c
;Wait for the Clipboard to fill.
ClipWait
;Perform the RegEx find and replace operation,
;where "ABC" is the whole-word we want to replace.
haystack := Clipboard
needle := "\b" . "ABC" . "\b"
replacement := "XYZ"
result := RegExReplace(haystack, needle, replacement)
;Empty the Clipboard
Clipboard =
;Copy the result to the Clipboard.
Clipboard := result
;Wait for the Clipboard to fill.
ClipWait
;-- Optional: --
;Send (paste) the contents of the new Clipboard.
SendInput, %Clipboard%
;Done!
return