12

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?

dvcolgan
  • 824

4 Answers4

6

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
}
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

mems
  • 374
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.

Stoikerty
  • 141
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.

Orwellophile
  • 549
  • 6
  • 9