The purpose is for gaming and I want to remap the Winkey to some other key so the Start Menu doesn't pop on when I hit it, and I want to disable Winkey shortcuts like Winkey+e (which opens explorer.exe) while I'm in a game.

This is what I've tried so far:

#IfWinActive ahk_class LWJGL
    LWin::p
    return
    LWin & e::e
    return
#IfWinActive

Remapping doesn't get picked up by the games, Lwin is treated as Lwin but the Start Menu is blocked which is half of what we were aiming for.

But, if I press and hold the Winkey then the e key it opens explorer.exe which is not intended, I wish the p key and e key to have been pressed at this step.

Is there any AHK expert out there that has accomplished this?

I tried blocking the shortcut like this:

#IfWinActive ahk_class LWJGL
    LWin::p
    return
    Lwin & e::
    return
#IfWinActive

But it would only send the p key, it omits the e key.

I also tried using the Send command with Up command like this:

#IfWinActive ahk_class LWJGL
    LWin::p
    return
    LWin & e::
        Send {LWin Up}
        Send {e Down}
    return
    e Up::Send {e Up}
    return
#IfWinActive

Everything's fixed except the e key does nothing on it's own (pressing it solely does nothing, it only works if LWin is pressed and then e is pressed). Please note that the first issue is also not resolved here which means the LWin key is not remapped to p in the game.


The particular game that I'm testing on these scripts is Minecraft, but I also tested this on CS:GO and the LWin key doesn't get remapped to p, it's still treated as Winkey. This is not the case on Notepad.exe or other non-game programs, LWin::p remaps Winkey to p.

  • Try also ~LWin Up:: return and ~RWin Up:: return. See also this article. – harrymc Dec 1 at 20:07
  • @harrymc That will permanently disable the Winkey! Not what I was looking for, and the article edits the registry which means I will lose the functionality of Winkey outside games, an app like SharpKeys remaps Winkey completely through registry but I want to be able to use the Winkey outside of the games. – Shayan Dec 1 at 20:50
  • You can limit its effect via #IfWinActive, as you did above. – harrymc Dec 1 at 21:18
  • But the point is, I want to use the Winkey for in-game keybindings... – Shayan Dec 1 at 22:49
  • 1
    This is a very problematic key to use this way. Another solution might be better. – harrymc Dec 2 at 8:00
up vote 1 down vote accepted

Windows key is a problematic key to remap in AutoHotkey. This is because it cannot actually prevent Windows from seeing that Windows key was pressed, so it needs to send extra simulated keystrokes to prevent start menu from opening. Your best bet for reliability in gaming is the following:

First remap the key using SharpKeys to a key that doesn't exist on your keyboard, like F15. Then remap this key separately for the cases when you are in the game and when you are not:

#IfWinActive ahk_class LWJGL
    F15::p
#IfWinActive

#IfWinNotActive ahk_class LWJGL
    F15::LWin
#IfWinNotActive

(You don't need return statements for remappings or when a hotkey needs to execute only a single line.)

  • You're so smart.. I never thought of this. Thanks a lot for helping :D – Shayan Dec 2 at 20:02
  • There's just one tiny problem that I realized after 4 days.. Winkey+L Does not lock the computer anymore! and I tried Esc::DllCall("LockWorkStation") which worked but remapping it with Winkey did not work for example: Winkey & L::DllCall("LockWorkStation") or other combinations of Winkey did not lock the computer! – Shayan Dec 7 at 2:54
  • 1
    There is no Winkey in AutoHotkey; you would write it as LWin & l, or preferably as #l. However, that may not work either, since, from AutoHotkey's point of view, you are pressing F15, so F15 & l is probably better. Try both of them (#l and F15 & l) both inside and outside the #Ifs and see which works for you. (Remapped keys may or may not trigger other hotkeys depending on whether they are hook hotkeys, read more on here.) – Debie Downer Dec 7 at 14:32
  • Wow, That was an instant fix!! F15 & L works perfect!!! Thank you so much :D – Shayan Dec 7 at 15:54

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.