0

I am trying to remap Left Alt to Left Win and Left Win to Left Alt in AutoHotKey.

But I also want to have Shift + F11 to toggle these two remaps.

I know I can do:

LAlt::LWin  
LWin::LAlt

but what I can't figure out is the toggle. The following version fails:

Shift & F11::
Hotkey, LAlt, Toggle
Hotkey, LWin, Toggle
return

When I press Shift and F11, it will say:

---------------------------
test.ahk
---------------------------
Error:  Nonexistent hotkey.  The current thread will exit.

Specifically: LAlt

    Line#
    001: Return
    002: SetKeyDelay,-1
    002: Send,{Blind}{LAlt DownTemp}
    002: Return
    002: SetKeyDelay,-1
    002: Send,{Blind}{LAlt Up}
    002: Return
--->    006: Hotkey,LAlt,Toggle
    007: Hotkey,LWin,Toggle
    008: Return
    009: Exit
    010: Exit
    010: Exit

---------------------------
OK   
---------------------------

I've been scratching my head for hours.. Any input will be greatly appreciated!

Jay
  • 56,361
  • 10
  • 99
  • 123
Nik So
  • 16,683
  • 21
  • 74
  • 108

1 Answers1

0

I'm sure it is more verbose than necessary, but I just tried this script and it does something like what you're after. It might send you in the right direction, if nothing else.

#NoEnv
SendMode Input

IsRemapEnabled := false
SetRemapEnabled(false)

SetRemapEnabled(toEnabled) 
{
  global IsRemapEnabled := toEnabled
}

+F11::
  SetRemapEnabled(!IsRemapEnabled)
return

LAlt::
  if (IsRemapEnabled) 
  {
    Send,{LWin DOWN}
  } else 
  {
    Send,{LAlt DOWN}
  } 
return

LAlt up::

  if (IsRemapEnabled) 
  {
    Send,{LWin UP}
  } else 
  {
    Send,{LAlt UP}
  } 
return

LWin::
  if (IsRemapEnabled) 
  {
    Send,{LAlt DOWN}
  } else 
  {
    Send,{LWin DOWN}
  } 
return

LWin UP::
  if (IsRemapEnabled) 
  {
    Send,{LAlt UP}
  } else 
  {
    Send,{LWin UP}
  } 
return
Jay
  • 56,361
  • 10
  • 99
  • 123
  • thanks for the response; there is one difference between specifying the down/up separate and *directly* LAlt::LWin; for instance, 1) run the script 2) at this point, win is still win, alt is still alt, and if you open an explorer window, pressing alt once shows the menu bar(win7/vista), pressing alt again hides it; 3) press shift+f11;4)win is now alt; alt is now win; win+number still activates taskbar icon(win7); alt+tab is still alttab;5)shift+f11 again, 6) BUT this time, pressing alt once in the will show the menu; but pressing it the second time won't hide it. – Nik So Sep 20 '11 at 05:36