How to disable autohotkeys for specific programs

Solution 1:

Make a couple of context-sensitive exceptions that remap your key(s) to their default setting for those two programs.

Right-click the AutoHotkey icon in your taskbar and select AutoHotkey's Window Spy to find the ahk_class of the programs you wish to ignore. The ahk_class of the active window shows in the Window Title & Class section at the top of the Window Spy.

If you have the z key remapped in the rest of your system (for example), add the following code to map it back to z in a certain app only (Notepad in this example).

#IfWinActive ahk_class Notepad ; turns on context sensitivity 
z::z ; this just maps z to itself
#IfWinActive ; turns back off context sensitivity 

More info on AutoHotkey website regarding context sensitive hotkeys: http://www.autohotkey.com/docs/commands/_IfWinActive.htm

Solution 2:

You could make a function to check if the current program is one that you'd like to ignore. Then for each of your hotkeys call the function and make a decision based on if it is the application you wish to ignore. The code includes a commented line that returns a variable that is the hotkey if you want it to have its regular behavior.

; Applications you want to disable joystick keybindings  
dont_joystick()                          
{                                                          
  IfWinActive,ahk_class VirtualConsoleClass 
    Return 1
  IfWinActive,ahk_class VIM
    return 1                                             
}                                                          

^p::                                                       
  If dont_joystick()                                            
    ;Do nothing
    ;Send %A_ThisHotkey% ; sends ^p in this case
  Else                                                     
    Send {Up} ;send hotkey                                             
  Return 

Where 'VirtualConsoleClass' and 'VIM' are the ahk_classes determined by using Autohotkey's window spy.