问题
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