AutoHotKey - Custom shortcut to switch to next/previous desktop in Windows 10

Solution 1:

Sometimes when you are trying to send modifier keys (win/ctrl/alt) and the triggering string has modifier keys as well, you need to wait for the triggering keys to be released, or they will affect the replacement string as you are finding out.

Try using KeyWait to accomplish this. Notice we are now using hotkey syntax vs hotstring

#LAlt:: ; switch to next desktop with Windows key + Left Alt key
  KeyWait LAlt
  SendInput #^{Right}
  Return

#LCtrl:: ; switch to previous desktop with Windows key + Left CTRL key
  KeyWait LCtrl
  SendInput #^{Left}
  Return

For purposes of switching desktops the above worked for me.

On other occasions, there are times when even this approach doesn't work, and there is another possible solution. Instead of key waits like these...

KeyWait LAlt
KeyWait LCtrl

...replace with the corresponding one of these keystrokes to clear the state of the key:

Send,{LAlt Down}{LAlt Up}
Send,{LCtrl Down}{LCtrl Up}