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?

3 Answers 3

15

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   
Sign up to request clarification or add additional context in comments.

Comments

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  

2 Comments

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?
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.
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.