I have an HP Laptop and I finally got around to changing the BIOS setting to reverse the annoying Fn+Function Key "feature" since I regularly F2, F5 & F11 with VBA & Office (a lot more often than I need to change screen brightness, etc)...

People can do whatever they want with their function keys behind closed doors, but mine were finally back to being real function keys, as God intended.

However I missed having the convenience of the function keys that acted as Media Keys to control VLC, Winamp & Spotify: F6F7F8F9 🔈-F10 🔈+F11 🔇

So I installed AutoHotKey to remap some of them back to the HP defaults:


This works but I would like to use F11 for both Volume_Mute and to open the VBE window in Access/Excel (normally Alt+F11 functionality).

  • Is there a way (with or without AutoHotKey) to set it up so that the key will behave differently depending on which window is active?

    If ActiveWindow is {Excel or Access} then:

    Alt+F11 remains as Alt+F11

    If any other window us active then:

    F11 AutoHotKey: Volume_Mute

  • if that's not possible, what would my script look like to map like:

    Alt+F11 remains as Alt+F11


    F11 AutoHotKey: Volume_Mute

There's another change or two I'm debating, but with an answer to this, I should be able to figure out the rest. Thanks!

(HP Folio 13 Windows 7 64bit)

  • 2
    You can make a hotkey definition context-sensitive by using the #If or the #IfWinExist/#IfWinActive directive. Dec 4, 2017 at 5:17
  • 1
    I agree, AutoHotKey can check for a window title, and so an AutoHotkey script should be able to have a condition that provides the flexibility needed to accomplish the desired goal.
    – TOOGAM
    Dec 4, 2017 at 6:05

1 Answer 1


Use an #If statement to selectively enable a hotkey. You can change the WinTitle if you like as well.

#If Not (WinActive ("ahk_exe excel.exe") Or WinActive ("ahk_exe access.exe"))
#IfWinActive ; make sure all hotkeys after this are not qualified with the above #If statement

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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