当我编写这样的 AHK 脚本时:
::abc::alphabet
Run Code Online (Sandbox Code Playgroud)
它就像魅力一样。唯一的问题是,当我想要复制的文本部分(包括我想要自动替换的内容的内容)时,它不想替换它。
例如:
!INS::{Ctrl Down}c{Ctrl Up}{Tab 2}{Enter}{Ctrl Down}v{Ctrl Up}
Run Code Online (Sandbox Code Playgroud)
让我复制,abc但是当它被粘贴时,我没有得到alphabet(如之前定义的)。
有没有办法让它替换复制和粘贴的单词?比如当我使用send命令发送一行或一些包含我想自动替换的单词的单词时?
Hotstrings只影响你实际输入的内容。要在剪贴板上执行搜索和替换,您可以使用RegExReplace命令。
下面是一个脚本,它复制选定的文本,然后粘贴修改后的内容(在搜索和替换之后)。我相信这就是你的意思:
#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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7905 次 |
| 最近记录: |