Nerding out in the autoexec
Been geeking out in the autoexec this morning.
For the last like 8+ years I've used the Coolermaster Masterkeys Pro M for my keyboard, which is like a fullsize keyboard but with the HOME, INSERT island merged with the numpad.
I think it's a great layout, but since I fixed my desk posture recently I'm hitting the keyboard with my mouse while playing CS. I picked up a used Redragon K683 on ebay which is a 60% layout. No numpad. It's also unfortunately an ANSI layout keyboard, I prefer ISO but for the price (£50) I can deal with that.
This raises a big issue for me, though. For the entire time I've played CS I've had "buy binds" bound to my numpad. When I press a certain button on my keyboard during freezetime in CS, it'll buy a certain piece of equipment. I don't want to get rid of muscle memory I've had for almost a decade so I needed to figure out a solution.
That solution ended up being to use aliases to create a "virtual numpad" on my keyboard when I hold down a certain key.
//---------------------------------
// Buy Binds
//---------------------------------
bind "kp_7" "buy ak47; buy m4a1"
bind "kp_8" " buy vesthelm; buy vest"
bind "kp_9" "buy vest"
bind "kp_4" " buy flashbang"
bind "kp_5" " buy smokegrenade"
bind "kp_6" " buy molotov; buy incgrenade"
bind "kp_1" " buy hegrenade"
bind "kp_2" "buy p250"
bind "kp_3" "buy defuser"
bind "kp_del" "buy deagle"
bind "kp_plus" "buy fiveseven; buy tec9"
Nothing too fancy, there are some that don't really get used all that much. I usually use the buy menu for the pistols so a couple of those will not be present on the new version.
So, first I need to figure out which key I want to use for this virtual numpad to appear. I don't want it on any of the major movement keys so Shift and Ctrl are out. I use Alt as a noclip bind for practice so that's probably a no go too.
That leaves Tab. But that's a scoreboard bind? How will I have both of them work at the same time?
Counter-Strike has possibly one of the best developer consoles in gaming. I mean that sincerely. The alias system allows you to basically create commands of your own, you can bind those to keys and you can even print text into the console with the echo
command.
Aliases are going to form the bedrock of this system.
Due to some limitations in the console, you can't nest quotes easily. Backslash doesn't escape quotes like it would in a lot of languages/json (to my knowledge). As a result, we're going to need a lot of aliases.
Take a look at the AK/M4 bind, for example. We have two commands bound to the same key, which requires quotes to denote the string we'd like to bind to kp_7
.
Therefore we need to extract the buy command string into its own alias.
alias buyPrimary "buy ak47; buy m4a1"
Creating this alias means that if we type buyPrimary
into the console and hit enter, it will fire off the two commands in the second string.
Now we need another alias to bind buyPrimary to a key on the keyboard, in this case I'm using i
to substitute kp_7
.
alias bindi "bind i buyPrimary"
With this alias created, we need another key to reset the i
key to how it was before.
alias reseti "unbind i"
In my case, there was nothing bound on the i
key anyway, so I can unbind it. The /
key is a different story however. This is the relevant config for that key:
alias bindslash "bind / buyKit"
alias questionmark "say ?"
alias resetslash "unbind /; bind / questionmark"
The slash key is a bind for shit talk that drops a question mark in the chat when I hit it. Nice.
Tying all these aliases together looks something like this:
alias +buybinds "bindi;bindo;bindp;bindk;bindl;bindsemicolon;bindcomma;binddot;bindslash; echo ---buybindson---";
alias -buybinds "reseti;reseto;resetp;resetk;resetl;resetsemicolon;resetcomma;resetdot;resetslash; echo ---buybindsoff--"
Why + and -? I'll explain:
In Counter-Strike, all movement is done with commands that start with either a plus or a minus. If you press W down, it activates the +forward
command, which makes you move forward. When you release W, it activates the -forward
command, which stops you moving forward.
You can create plus and minus aliases to do different actions when a key is pressed and when it is released.
In our case, we want two actions to run when tab is held down: the scoreboard to show and the buybinds to activate.
So you'd think we could do something like this:
bind tab "+showscores; +buybinds";
Unfortunately, the + and - binding only applies to the first command in the chain, so we need to create an intermediate alias to do both of these actions.
alias +plustab "+buybinds; +showscores";
alias -plustab "-buybinds; -showscores";
bind tab "+plustab";
You don't need to worry about binding the - action. The game will figure it out.
Counter-Strike has a really powerful console if you can learn some of the details. Aliases give you a really powerful platform to make the binds you want, when you want.
You may remember when Valve removed nullbinds a while ago when snaptap was at its peak popularity. I was really worried they would remove aliases altogether, their solution ended up being incredibly well thought out which means we can still do cool stuff like this in configs.
My config is open source so feel free to poke around and steal some bits. I've slowly honed it over the last 8+ years.
email: harry [at] hjb [dot] dev
discord: indexgg