Can AutoHotKey switch layouts?

So, I'm trying to write a simple script in AutoHotKey that will use NumLock (which I matched with a capsule in my registry) as a switch to turn my directional keys into numpad nab keys. My script looks like this:

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 when Up is repeated on line 15. How can I tell AutoHotKey to return my keys to their original key designation? I tried to leave the "else" field empty, not the "if state = U" section, but when I switch again, the keys remain in their changed state. I am sure there is something simple that I am missing.

+4
source share
2 answers

Ah, here you go. You cannot do it the way you are trying to do it. Since you can only display one key in a script, put the if / function inside the hotkey, for example:

 GetKeyState, state, NumLock, T up:: if(state = D){ send {Numpad8} }else{ send {up} } return 
+3
source

This is a simplified solution that uses # If context .

The advantage of this is that you do not need to have If statements to reassign the key back to yourself 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 
+2
source

Source: https://habr.com/ru/post/1490062/


All Articles