Team Fortress 2

Team Fortress 2

Not enough ratings
Changing key bindings for any game
By Karlovsky120
This guide will show you how to change key bindings for any game (or program) on your computer.
   
Award
Favorite
Favorited
Unfavorite
Changing key bindings
AutoHotkey (AHK) is a powerful scripting program that can change the key bindings in programs running on your computer.

You can download it from here.[ahkscript.org]

Make sure you install ahk2exe, too (you will be asked)!

Once you installed AHK, right-click on desktop and select new>AutoHotkey script. Name it whatever you wish.

Right-click on the ahk file and chose Edit Script. It will open the script in Notepad. If there is already anything written in the script, leave it and write below it.

Copy this to the script:
#IfWinActive ahk_class Notepad

This line of code will make it so the script runs only when Notepad window is active.
We will use this to make sure that your key bindings are only applied to certain games and programs.

Now put this in a new line:
a::b

This bit will make it so that whenever you press "a" on the keyboard, notepad will think you pressed "b". You can also add more key bindings below one another.
First key is what you press and one after the double colon is the one the game will think you pressed. For full list of key names click here.[ahkscript.org]

I'd also like to point out that the binding doesn't have to be for a single key, you can bind keystrokes, too. For more info on how to do that, click here.[ahkscript.org]

Now save the script and run it. You will notice a new icon in the task bar. Right click on it and click on Window spy. Now try clicking on any window you have open.

If you clicked on notepad, the second line in the top box will say:
ahk_class Notepad

This is how you will find out what the window of your game is called and put it on that first line we entered. Window names can be really quirky for some games so you can add a comment above it so you know for which game the key bindings are. The comments use semicolons and look like this:
; This is a comment

By now you should have everything you need to change the key bindings of your favorite game!

You can also stack key bindings for different programs below one another. Here I have my setup for Serious Sam: the Random Encounter (and Notepad, just to show an example of multiple programs):
; Serious Sam: the Random Encounter #IfWinActive ahk_class TRunnerForm Space::z q::x w::Up a::Left s::Down d::Right ; Notepad #IfWinActive ahk_class Notepad a::b b::c d::e e::a c::d

When you install a new game, you can just add the new bindings below!

Optional step:
Once you're done, you can right click on the script and choose Compile Script. This will create an *.exe file that will run your script. You can put it in the startup folder so you don't ever have to worry if the script is running or not when you are starting your game. Just make sure you don't loose the *.ahk file in case you wish to add another game, or edit a binding for a specific key.


I hope that it goes without saying that you can use this on virtually ANY program you have on your computer.

Now that you have done all this, I just want to tell you that we barely scratched the surface of AHK. It is a very powerful tool that can be used to accomplish much more. If you want to learn more about it click here.[ahkscript.org]

Hope this helps!
11 Comments
taji Jan 1, 2024 @ 11:25pm 
i'm confused about what/where the "startup folder" you're talking about is. is it game specific? or in a steam directory or something? this is helpful tho!
Ryaskar Nov 1, 2023 @ 4:08am 
This works well, but whta might be better to really just use the Keybindings on one specific window would be to use the "ahk_pid" as the ahk_clas can be multiple different windows, like one game for me has the same ahk_class as my browser, so that was a bit annoying, but with ahk_pid it works perfectly!
raventhecat22 Jun 6, 2022 @ 9:52am 
Does this program work well with games made on Unity?
DinoTuesday Jan 9, 2022 @ 6:04pm 
This helped me a lot with Going Under, since my mouse is currently not connecting. It took a while to troubleshoot the scripting but I learned a bit and think I could do this for really any game or program now which makes it a versatile tool. Thank you!
⭕⃤ BIPPO Jul 26, 2020 @ 5:06am 
Thank you, you saved my life with this!!
AstrayCuriosity Jan 27, 2020 @ 6:26am 
nah I just dropped and forget about it. I tried anything and it still didn't work but it did something actually. It disable the default key in the game at all. Let's say I tried to bind T key for one command to Y and the result is T key just stopped working and not responding with Y do nothing in the same time.
Karlovsky120  [author] Jan 27, 2020 @ 5:53am 
Wow, I should really look at my notifications more often.
I hope you figured it out by now, but you have to figure out what the name of the game window actually is. It's not necessarily the name of the game. Use Windows spy, as described above.
AstrayCuriosity Oct 6, 2019 @ 11:44pm 
I hope it's not necroposting. I completely don't get it. Like if I want to change the game button is should look like this?

; just comment
#IfWinActive ahk_class "gamename"
u::c

ahk_class not ahk_exe? I typed the game name correctly, tried other ways and still nothing seem to work.
Karlovsky120  [author] May 29, 2018 @ 5:17am 
Sorry, I haven't dabbled with this for a few years now. I forgot how it all works, but google around a bit, I remember there being a lot of guides on how to do a lot of different things with this, what you are trying probably being one of them.
8-bit May 28, 2018 @ 6:11pm 
Thank you very much for the guide! I do have trouble using it though. I followed your instructions and on three different games what would happen rather then change the keys around the script would disable both keys. Im not sure what I did wrong, below is a copy of my script for one of my games Alien Splatter:

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

#IfWinActive ahk_class Mf2MainClassTh
a::n
s::z


When I run the script it just disables the a,n,s,and z keys :steamfacepalm: any help would be awesome thanks!