Autohotkey:通过关联数组替换文本选择

时间:2018-01-08 12:54:56

标签: autohotkey

我想用Autohotkey实现以下行为: 按下Control + Shift + P后,当前选择的文本应替换为存储在字典中的值。

我尝试了以下内容:

^+P::
    Send, ^x ;cut current text selection
    dict := { "key1" : "value", "key2" : "value 2" } ; associative array
    Clipboard=%dict%.%Clipboard%
    Send, ^v ;paste back treated text

然而,只打印出以点开头的当前剪贴板内容。似乎甚至没有创建关联数组。我错过了什么?如何检查字典中是否包含密钥?

1 个答案:

答案 0 :(得分:3)

这将使用存储在字典中的值替换当前选定的文本

dict := { "key1" : "value", "key2" : "value 2" }

^+P::
    Send, ^x
    ClipWait 1
    send % dict.HasKey(clipboard) ? dict[clipboard] : "???"
相关问题