Search code examples
keyboardkeyboard-shortcutsautohotkeyautohotkey-2

How to remap window key press to a shortcut


I would like to use the window key to open an app launcher, which has its own shortcut (alt + space), while also preserving the combination shortcuts (win + 1, win + d, win + tab, etc.). I have tried many different approaches, but have not been successful. My most successful attempt looks like this:

#Requires AutoHotkey v2.0

$LWin up::
{    
    if A_PriorKey = "LWin"
        Send "!{Space}"
}

This code allows me to open the app launcher, but all other shortcuts stop working. What seems to be happening is that this hook also consumes the LWin key when it's pressed down (meaning the operating system doesn't register the key press).

I would like to react only to the key release event and leave the key press event untouched. In most cases, I think I’m fine with consuming the key-up event, but it would be great if I could consume it only when the if condition is fulfilled.

I'm not tied to AutoHotkey; I installed it just for this one task. I normally use PowerToys for regular remapping. If you have another solution that could help, I'm happy to switch to it.


Solution

  • This works here:

    #Requires AutoHotkey v2.0
    
    ; https://www.autohotkey.com/docs/v2/lib/A_MenuMaskKey.htm
    ; Disable the ability for the left Win to activate the Start Menu:
    ~LWin::Send "{Blind}{vkE8}"
    
    ~LWin up::
    {   
      if A_PriorKey = "LWin"
        Run "Notepad"  ; Send "!{Space}"
    }