Reputation: 41
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.
Upvotes: 4
Views: 1614
Reputation: 2999
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
Upvotes: 3
Reputation: 6371
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
Upvotes: 3