0
votes

I have a AutoHotKey script that asks me if I want to remap my Win keys to Ctrl or cancel their remapping, thus making them Win keys again.

However I cannot find a way to cancel the remap. If I use the command LWin::Lwin I get the error message that there is a "duplicate key".

I'm new to AutoHotKey, but I did search first, so please don't bite my head off is this is a stupid question. (It is a Lenovo laptop with Windows7-64).

Here's the script:

MsgBox, 4, , Remap CTRL for Desktop Keyboard?
IfMsgBox, Yes
   LWin::LCtrl
   RWin::RCtrl
   return
; Otherwise, the user picked No
;   LWin::LWin
;   RWin::RWin
;   return
2

2 Answers

1
votes

Various ways.

Create a hotkey to close ahk, e.g. ^!x::ExitApp = [Ctrl]+[Alt]+[x]

Create a hotkey to disable/enable all hotkeys e.g. f12::suspend

Create hotkeys that ONLY work in a specific appliaction.

Here are all suggestions combined. Under normal circumstances: LWin::LCtrl and RWin::RCtrl are active, Unless you pressed F12. You can in AHK_L set variables that can be used in #If (Var = 1), where you can define Hotkeys that only work when that variable is set to 1 (true).

SetTitleMatchMode, 2 ; Allow the use of a portion of the wintitle
F12::
Suspend
If A_IsSuspended
    TrayTip, HotKeys, Off, 3, 0
Else
    TrayTip, HotKeys, On, 3, 0
Return

^!x::ExitApp
LWin::LCtrl
RWin::RCtrl
F1::MsgBox, Normal Mode

#IfWinActive, Window title
  F1::MsgBox, Window X is active
  F2::MsgBox, You pressed F2 inside Window x
#IfWinActive

Toggle := False
F10::Toggle := !Toggle ; Turns Mouse button ON|Off
#if Toggle ; ONLY worls in AHK_L
     LButton::Return ; Disables Mouse button
#if
-1
votes

Here's a version you can drive from the command line:

; Allow the script to be reloaded multiple times
#SingleInstance force

; Check the command line for input
NumberOfParameters = %0%

; If any command line param was passed then just unload the mappings
If ( NumberOfParameters > 0 )
{
  MsgBox Command line parameter was passed, unloading...
  ExitApp
}
Else
{
  ; Let's ask the user what they want to do
  MsgBox, 4, , Remap CTRL for Desktop Keyboard?

  IfMsgBox, Yes
  {
    ; If yes, then remap
    MsgBox Keys have been mapped.
  }
  Else
  {
    ; If no, then unload
    MsgBox Unloading mapping.
    ExitApp
  }
}

; Keys will be mapped so long as the script remains resident
LWin::LCtrl
RWin::RCtrl