Can AutoHotKey toggle keymapping?

自闭症网瘾萝莉.ら 提交于 2019-12-12 11:21:57

问题


So I'm trying to write a simple script in AutoHotKey that will use NumLock (which I have mapped to the capslock in my registry) as a toggle to turn my directional keys into the numpad nab keys. My script is as follows:

GetKeyState, state, NumLock, T
if state = D
{
    Up::Numpad8
    Down::Numpad2
    Left::Numpad4
    Right::Numpad6
    Enter::Numpad5
}
if state = U
{
    $Up::Up
    $Down::Down
    $Left::Left
    $Right::Right
    $Enter::Enter
}
Return

However, I get an error saying Up is repeated in line 15. How do I tell AutoHotKey to return my keys to their original key designation? I tried leaving an "else" section blank as opposed to the "if state = U" section, but then the keys remain in their altered state when toggling again. I'm sure there is something simple I am missing.


回答1:


Ah, here you go. You can't do it the way you are trying to do it. Since you can only map the key once in the script, put the if/or function inside the hotkey, like so:

GetKeyState, state, NumLock, T

up::
    if(state = D){
        send {Numpad8}
    }else{
        send {up}
    }
return



回答2:


This is a simplified solution that uses the #If context.

The advantage of this is that you will not have to have If statements to remap a key back to itself in the Else statement. The key will retain its normal functionality if the condition is not true.

#If GetKeyState("NumLock", "P")
    Up::Numpad8
    Down::Numpad2
    Left::Numpad4
    Right::Numpad6
    Enter::Numpad5
#If


来源:https://stackoverflow.com/questions/17506736/can-autohotkey-toggle-keymapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!