8

I am a newbie to Autohotkey, and I can't figure this out despite reading through this site and the official documentation.

I just want to have certain hotkeys work only with certain applications. So for example, if I press spacebar in a certain game I want it to send ` (grave), but if I'm not in that game I want spacebar to function normally. Everything I try seems to make spacebar do nothing when I'm not in game. I can try using an "else" statement to send the spacebar, but that just seems to make an infinite loop. Help!

EDIT: Thank you NbdNnm. Here's exactly what ended up working for me:

#IfWinActive League of Legends (TM) Client
Space:: `
#IfWinActive

user1843366
  • 83
  • 1
  • 4
  • You should be able to change the code to just `#IfWinActive League of Legends`. The default Title Match mode does not require full match so the `(TM) Client` may be a liability if they add the build number to the title, say `League of Legends (TM) v1.001 Client` – Nelson Jun 12 '14 at 15:40

1 Answers1

9

Try this and make sure you have the latest version of AutoHotkey. Put the application process name in the strYourAppExeName variable and put your hotkey definitions in the #if block.

strYourAppExeName := "notepad.exe"
strYourMessage := "``(grave)"

#If WinActive("ahk_exe " strYourAppExeName)
    Space::SendInput, % strYourMessage
#if
NbdNnm
  • 528
  • 2
  • 11
  • The built-in Window Spy utility can be useful to determine the application name or ahk_class. It might also be useful to review the AutoKey Help topic, "IfWinActive / IfWinNotActive." – EJ Mak Jul 13 '15 at 17:17
  • How to do this for Microsoft store apps as OneNote for Windows 10? – Sensebe Aug 10 '18 at 21:49