使用 AutoHotkey 将 [ 替换为 { 并将 ] 替换为 }

dar*_*ren 5 autohotkey

我发现在编码中我很少使用方括号,[]{}经常使用大括号。在大多数键盘上,这些是使用Shift+[Shift+输入的]

现在我尝试使用 AutoHotkey 重新映射这些键:

[::{{}
Run Code Online (Sandbox Code Playgroud)

添加{}基本上是原始模式,但它不起作用。接下来我试过了

{[}::{{}
Run Code Online (Sandbox Code Playgroud)

但这也不起作用。

有什么帮助吗?

igl*_*vzx 11

使用大括号进行原始密钥解释仅适用于发送命令。因此,要映射[{]}您可以使用:

[::Send, {{}
]::Send, {}}
Run Code Online (Sandbox Code Playgroud)

注意:Shift等效键重新映射键很麻烦,因为大多数键盘每次发送相同的扫描码,唯一的区别是Shift键的引入(它有自己的扫描码)。

例如,按下[我的键盘发送扫描码01A并产生一个[. 按LShift+[发送扫描码02A 01A,产生一个{.


更新:

我已经通过一些巧妙的逻辑成功地克服了扫描码问题!使用以下格式,您应该能够使用其Shift对切换任何键。密钥重复也应该有效。

*$[::
    if (GetKeyState("Shift"))
        Send, {[}
    else
        Send, {{}  
    return

*$]::
    if (GetKeyState("Shift"))
        Send, {]}
    else
        Send, {}}
    return
Run Code Online (Sandbox Code Playgroud)

扩展这个想法,@Bob编写了一个更强大的脚本版本:

*$[::
    if (GetKeyState("Shift"))
        SendInput, {[ Down}
    else
        SendInput, {{ Down}
    return

*$]::
    if (GetKeyState("Shift"))
        SendInput, {] Down}
    else
        SendInput, {} Down}
    return

*$[ Up::
    if (GetKeyState("Shift"))
        SendInput, {[ Up}
    else
        SendInput, {{ Up}
    return

*$] Up::
    if (GetKeyState("Shift"))
        SendInput, {] Up}
    else
        SendInput, {} Up}
    return
Run Code Online (Sandbox Code Playgroud)