Switch Ctrl and Alt with AutoHotKey without messing up the Alt-Tab switcher?
Solution 1
I would like switch Alt and Ctrl because I'm currently a Mac user on Window (with a PC keyboard). All hotkeys on Mac: Cmd+n, Cmd+w ... -> PC: Ctrl+n, Ctrl+w and Cmd got same place as Alt key.
I found a non perfect solution:
Map all letters like that :
LAlt & a::Send {LCtrl Down}{a}{LCtrl Up}
...
LAlt & z::Send {LCtrl Down}{z}{LCtrl Up}
LCtrl & a::Send {LAlt Down}{a}{LAlt Up}
...
LCtrl & z::Send {LAlt Down}{z}{LAlt Up}
And you will keep Alt+Tab and AltGr functional
This is my full implementation (non complete): http://www.pastie.org/1660132
Solution 2
I was looking for the same thing and found something that works without plugins or other programs. You can do it using the registry as described here.
Alternatively, just create 2 reg files. First the file for switching the Ctrl Key to Alt.
switch_ctrl-to-alt.reg
This adds the necessary key to the registry.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,03,00,00,00,1D,00,38,00,38,00,1D,00,00,00,00,00
And then the file for switching the Alt back to the Ctrl key.
switch_alt-to-ctrl.reg
This removes the necessary key from the registry.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=-
After double clicking the reg-file you need to restart and you're good.
Solution 3
This works for me:
; First, swap LAlt and Ctrl
LAlt::Ctrl
; This reverts the Alt+Tab behavior
^Tab::
Send, {LAlt Down}{Tab}
ReleaseLAlt(10000)
; The purpose of this function is to release the LAlt key
; Without this, the LAlt key will be stuck
ReleaseLAlt(timeout := "")
{
startTime := A_Tickcount
while (isaKeyPhysicallyDown("LAlt"))
{
if (timeout && A_Tickcount - startTime >= timeout)
Send, {LAlt Up} ; Took too long
sleep, 50
}
Send, {LAlt Up}
}
isaKeyPhysicallyDown(Keys)
{
if isobject(Keys)
{
for Index, Key in Keys
if getkeystate(Key, "P")
return key
}
else if getkeystate(Keys, "P")
return Keys ;keys!
return 0
}
Solution 4
If you are a Mac user (or even if you're not), it's possible you think you want to swap Control and Alt, but perhaps all you actually require is swapping
Alt-A through Alt-Z and a few extra keys (Arrows, [ and ]).
Try this, for testing purposes I only have it active in Chrome.
#IfWinActive ahk_exe chrome.exe
![::Send !{Left}
!]::Send !{Right}
!a::Send ^a
!b::Send ^b
!c::Send ^c
!d::Send ^d
!e::Send ^e
!f::Send ^f
!g::Send ^g
!h::Send ^h
!i::Send ^i
!j::Send ^j
!k::Send ^k
!l::Send ^l
!m::Send ^m
!n::Send ^n
!o::Send ^o
!p::Send ^p
!q::Send ^q
!r::Send ^r
!s::Send ^s
!t::Send ^t
!u::Send ^u
!v::Send ^v
!w::Send ^w
!x::Send ^x
!y::Send ^y
!z::Send ^z
!Right::
Send {End}
return
*!Right:: ; This handles Shift-Right
Send {Blind}{LAlt Up}{End}
return
!Left::
Send {Home}
return
*!Left:: ; This handles Shift-Left
Send {Blind}{Alt Up}{Home}
return
You should be able to build on that. Those are the most frequent Mac short-cuts that get me.
Related videos on Youtube
Sulav Depp
Updated on September 17, 2022Comments
-
Sulav Depp over 1 year
I want to switch the Ctrl and Alt keys in Windows XP. I created an AutoHotKey script that contains the following:
LAlt::LCtrl RAlt::RCtrl LCtrl::LAlt RCtrl::RAlt
This works, but the only problem is that the Alt-Tab switcher gets stuck. When I release Alt-Tab, the window switcher stays up until I hit another key or click the mouse.
Does anyone know how to fix this problem?
-
Sophistifunk over 11 yearsDo you have problems with this causing the key-up for alt being missed? It's definitely happening for me.
-
doctorw0rm almost 8 yearsThis is an extremely smart answer. I would add two thoughts to it: 1. Remapping Alt+Backspace to Ctrl+Backspace (something Mac users do all the time). 2. Figuring out some way to map Alt+q to Alt+F4, though I'm not sure how to do that and continue to preserve the other functionality of rebinding Alt Q to Ctrl Q.
-
Anand Bhararia almost 8 yearsWell, I was/am a Mac user on a hackintosh platform, which means I never stopped using a PC keyboard. As a result, we (PC owners) generally swap "Option" and "Command" within OS X Keyboard settings. That means when we revert to windows, our Command key is our Alt key, and Command-Tab is naturally the same as Alt-Tab. What I cannot understand however, is why people keep talking about rebinding the Control key. There's just not that many OS X shortcuts that involve the control key. BTW, remapping Cmd-Q (Alt-Q for me) to
WinClose, A
would fix that for you. -
gabe over 5 yearsThis worked the same as superuser.com/a/1202601/222702 by switching the logic Ctrl and Alt keys between their physical keys, but it does not maintain using the physical Alt key for Alt-Tab switching (which is what I think the OP and I are looking for). +1 for including the key removal file.
-
Teoman shipahi over 2 yearsThis is a pretty neat solution, and 10 seconds is pretty enough time to roll button back :)