17

While using AutoHotKey I wanted to setup a rule to swap the left alt and left ctrl. I can do this by doing:

LAlt::LCtrl
LCtrl::LAlt

I then wanted to keep the 'alt tab' functionality bound do those physical keys, thus I tried

LCtrl & Tab::AltTab

In addition to the two uptop, yet it won't work. If I put it like so:

LCtrl & Tab::AltTab
LAlt::LCtrl
LCtrl::LAlt

Then the tab will work, however the ctrl alt swap will be broke. Any suggestions?

whomba
  • 387
  • 5
  • 13

3 Answers3

14

The hotkey documentation talks about wildcards

Wildcard: Fire the hotkey even if extra modifiers are being held down. This is often used in conjunction with remapping keys or buttons. For example:

*#c::Run Calc.exe ; Win+C, Shift+Win+C, Ctrl+Win+C, etc. will all trigger this hotkey.

*ScrollLock::Run Notepad ; Pressing Scrolllock will trigger this hotkey even when modifer key(s) are down.

So try this

*tab::
{   if(GetKeyState("LAlt", "P"))  
{   Send {LControl up}{Alt down}{tab}
    KeyWait, tab  
}else   
{   send {tab}
}      
return
}          
~LAlt Up::
{   send {lalt up}
return
}
LAlt::LCtrl 
LCtrl::LAlt   
Community
  • 1
  • 1
JPGInc
  • 215
  • 1
  • 8
6

I improved this slightly to fix shift tab not working, now you can use Shift+tab as expected where as before you couldn't (was frustrating trying to fix indentation(outdent) when coding) I may improve this more and get Shift+Alt+Tab working

*tab::
{   

if(GetKeyState("LAlt", "P")){   
    Send {LControl up}{Alt down}{tab}
    KeyWait, tab  
} else if(GetKeyState("LShift", "P")){
    Send {LShift down}{tab}
    KeyWait, tab 
}else   
{   send {tab}
}      
return
}          
~LAlt Up::
{   send {lalt up}
return
}
LAlt::LCtrl 
LCtrl::LAlt  
Mwiza
  • 7,780
  • 3
  • 46
  • 42
Joshua Cave
  • 171
  • 2
  • 2
  • This was the closest I could find on the net, but after copying your code above the (as written on the keyboard) alt-tab still didn't work for me (Surface Pro 3, 8.1). Neither did the (as written) ctrl-tab. Did you have any alt-tab style functionality after doing this? – Chris Oct 11 '14 at 03:13
  • Coming from a mac and switching to a windows machine for a job, I found no problems with the above script on a Lenovo T470. – Roy Scheffers Jan 24 '20 at 08:14
1

Just ran into the same problem myself, was looking for a more straightforward solution. If you swap Alt and Ctrl using SharpKeys (or other registry remapping tool) from there it's a simple:

RCtrl & Tab::AltTab

Ryan
  • 21
  • 1