Search code examples
windows-10keyboard-shortcutsautohotkey

Autohotkey: Remap Win key - when pressed alone


Because of an insane laptop keyboard layout and the inability to map Fn-combinations I want to do a few remappings. I would like to use the LWin key as modifier (such as LWin+Right ==> End, etc.). It works just fine.

However, I want to stop LWin, when pressed and released alone, to bring up the Windows menu (b/c I sometimes press the modifier but then decide not to complete the action) and I still want to be able to access the Windows menu fairly easily, say via LAlt+LWin. (Obviously LWin must act as a proper modifier otherwise.)

So I tried:

#LAlt::Send {LWin}

which kinda works but ugly (needs LWin kept pressed while Alt is pressed and released). It would be more natural the other way round, i.e.

!LWin::Send {LWin}

but it doesn't work (not even with a $ or ~ prefix).

Worst of all I have had no success disabling the LWin key alone in such a way that it still works as a modifier:

LWin::Return

kills it completely.

I'm new to autohotkey (have had luck with keyboards, I guess ;)); what's a good way to solve these?


Update: here is my hotkey file in full so far:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#InstallKeybdHook

; Win + arrows
*#Right::Send {End}
*#Left::Send {Home}
*#Down::Send {PgDn}
*#Up::Send {PgUp}

; Sane CapsLock: make it Shift, Shift+CapsLock as CapsLock
CapsLock::Shift
+CapsLock::CapsLock

; Alt-Win to Win (so that Win menu is accessible still)
;   and disable Win alone (so that it won't pop up with navigation)
;??????????????

Solution

  • This should work:

    LWin up::return
    <!Lwin::
        send ^{Esc}
    return
    <#right::
        send {end}
    return
    

    Using Ctrl + Esc instead of LWin here does the trick.