11

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?

4 Answers 4

5

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
}
2
  • All other solutions I've seen suffers this problem with alt stuck down, and if not you can't continuously tab. This is the best solution I've seen after digging for an hour.
    – davzaman
    Jun 24, 2023 at 23:20
  • I am trying to also map Alt-Tab to Ctrl-Tab. You can make the ReleaseLAlt function generalizable by changing the function signature to ReleaseKey(key, timeout := "") and changing "LAlt" to key and {LAlt Up} to {%key% up}. When calling the function change it to ReleaseKey("LAlt", 10000).
    – davzaman
    Jun 24, 2023 at 23:50
4

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

1
  • Do you have problems with this causing the key-up for alt being missed? It's definitely happening for me. Nov 27, 2012 at 5:40
4

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.

1
  • This 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.
    – gabe
    Nov 30, 2018 at 16:55
1

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.

2
  • This 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.
    – doctorw0rm
    Jul 18, 2016 at 3:52
  • Well, 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. Jul 18, 2016 at 5:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .