简体   繁体   中英

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, ie

!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)
;??????????????

This should work:

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

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

Another solution, especially for who want to remap depending on long-press or short-press.


For me, I only want to prevent the start menu when I had pressed down the win key and finally give up the next combination key ……

~LWin::__Disable_LWin()
            __Disable_LWin() {
                Send, {Blind}{vkFF}
                if (TickCount_When_LWinPressedDown = 0) {
                    TickCount_When_LWinPressedDown := A_TickCount
                }
            }
LWin Up::__Enable_LWin_ForShortPress()
            __Enable_LWin_ForShortPress() {
                if (A_PriorKey == "LWin") {
                    if (A_TickCount - TickCount_When_LWinPressedDown < 800) {
                        Send, {Blind}{LWin}
                    }
                }
                TickCount_When_LWinPressedDown := 0
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM