Counter-Strike 2

Counter-Strike 2

39 ratings
Keybinds with modifiers (Alt, Shift, etc.) and toggle/cycle binds
By mechalynx
How to create keybinds with modifiers, such as pressing Alt, Shift or something else to modify the behavior of a key.

Update: Added section on creating toggle and cycle binds, as well as how to echo text and play sounds.
   
Award
Favorite
Favorited
Unfavorite
Purpose
There are tons of guides on how to create config files and keybinds, but I've seen no explicit mention of how to create modified keybinds although some guides include them. Since this is a question some of us have but no easy source for the information seems to exist, I decided to put the instructions here for those who want to use modifiers.

This guide will not deal with the basics of configs, binds and scripting, nor will it go into any details on how binding or aliases work. If you're looking for something like that, here's a few guides I found here on Steam that are quite good:

(also, see the warning at the end of this section)

http://steamcommunity.com/sharedfiles/filedetails/?id=314801693
http://steamcommunity.com/sharedfiles/filedetails/?id=200552666
http://steamcommunity.com/sharedfiles/filedetails/?id=212073914
http://steamcommunity.com/sharedfiles/filedetails/?id=244970128

WARNING: The example binds here are examples, some of them silly - since keybinds persist after you close the game, DO NOT execute these unless you're prepared to restore your previous keybinds manually (or you already have them in your autoexec.cfg or config.cfg). They will overwrite yours - you have been warned, don't complain if you accidentally create a mess.
Simple modifier binds
In order to use a modifier in a bind, such as Alt to create the keybind Alt+F to pull out a flashbang, we need to use aliases since we can't have quotes within quotes.

Here is an example:

alias +plainjump "bind space +jump"; alias -plainjump "bind space +attack"; bind shift "+plainjump";

This binding will cause Space to shoot your weapon or jump if you press Alt+Space. This is obviously not very useful, unlike this:

alias +switchknife "bind q slot3"; alias -switchknife "bind q lastinv"; bind alt "+switchknife";

which will always switch to your knife when you press Alt+Q, while behaving as usual when you're not holding Alt. Since these snippets have semicolons, you can copy-paste the examples directly into your CS:GO console and they'll work.

IMPORTANT: Because of the way these binds work, if you press the modifier after the modified key (Q+Alt instead of Alt+Q in the second example) the key will behave as if you haven't pressed the modifier, since the binding is still in its original state. The behavior obviously won't change if you press the modifier while the modified key is active (for example, if you bind Space to shoot and Alt+Space to jump, you won't stop shooting if you press Space first and then Alt until you release the key and press Alt+Space in the proper order.

The above examples use held keybinds, but you can create toggle keybinds and anything you want - besides the aliasing and chaining of binds, they behave just like any other keybind.
Chained modifiers and non-standard modifier keys
You can also have multiple modifiers for a key, by modifying the modifiers. Here's an example:

alias +shjump "bind shift +plainjump"; alias -shjump "bind shift +speed"; bind alt "+shjump"

This creates the combination Alt+Shift+Space to jump, while Shift makes you walk when held alone.

You can bind any key the game allows you to create a keybind for as a modifier. You can modify Alt with F and 9 to buy a flashbang and jump:

alias +happybuy "buy flashbang; +jump"; alias +makealthappy "bind alt +happybuy"; alias -makealthappy "unbind alt"; alias +makefalty "bind f +makealthappy"; alias -makefalty "bind f +lookatweapon"; bind 9 +makefalty

Now, when you press 9+F+Alt you'll be very happy to get a flashbang (or you might say "apple", who knows).
Using Shift (or another key) to both perform its in-game action and as a modifier
Messed up your shift key and now you can't walk? Want to use modifiers for multiple different combinations? Here's how you do it.

This is an example of using the shift key to both walk, as usual, and modify our buyscript binds:

alias standardbuy "buy m4a1_silencer; buy deagle" alias sniperbuy "buy awp; buy deagle" alias +makestandard "bind KP_INS sniperbuy; +speed" alias -makestandard "bind KP_INS standardbuy; -speed" bind shift +makestandard bind KP_INS standardbuy

The important part is "+speed" and "-speed". Normally, shift is bound to "+speed", which toggles your walking. If you bind Shift, you no longer have that bind and are unable to walk (really funny when you're going all confident in a new match with your brand new buyscript binds and realise it mid-way).

In order to restore that, we need to add the walk toggle to the bind, so that Shift modifies that as well as whatever key you want modified normally.

In the above script, we alias our two states for the Insert key, because we can't have more than one pair of quotes in a script statement (as already explained above). Then we make the alias that will be applied to Shift - it binds the buyscript to the Insert key, depending on whether Shift is pressed or not and does the same for "speed". Then finally we bind the alias to Shift. The last line is just to make sure Insert has a default behavior (otherwise we'd need to press Shift once before Insert does anything).

To do this for other keys, all you need to do is bind it from the in-game settings menu (you'll lose your custom bindings on that key, if any) and type "bind KEY" in the console, where KEY stands for the key you set. Whatever it prints out, append that to the bind in your script just like we did above with "+speed".

Remember that if it's a held action (such as walking) you need to manually reset it in the keybind. If there was no "-speed" in the "-makestandard" alias, pressing Shift would cause you to walk permanently after pressing it once.
Toggle binds
Creating a bind that toggles an option or cycles between many is simple, but takes a bit of extra writing.

If you want to toggle a variable, such as `net_graph` you may be in luck, since `incrementvar` can do the job easily. However, it requires that whatever you want to toggle has either 2 states, or the states you want are spaced evenly.

bind j "incrementvar net_graph 0 1 1"

`incrementvar` in this case is told that `net_graph` has a minimum value of 0, a maximum of 1 and that it should increment it by 1 (this is the order of the arguments). `net_graph` in practice can go up to 3, but `incrementvar` doesn't care about what the variable can do, it just cares about what we want it to do.

This bind will toggle `net_graph` on and off and when it's on it will bet set to 1. It works as a toggle because when `incrementvar` sees an overflow, it wraps around back to 0.

Here's an example of toggling between two values that aren't 0 and 1:

bind j "sv_showimpacts 0 3 3"

This bind will toggle `sv_showimpacts` on and off, but when on it will have a value of 3, due to overflow after incrementing it from a value of 3, by 3. If we wanted to toggle between `sv_showimpacts 2` and `sv_showimpacts 3` we could do this:

bind j "sv_showimpacts 2 3 1"

It should be obvious now what the limitation is. If you have some variable that you want to toggle between two arbitrary values that aren't conveniently spaced apart, you'd have to get creative since `incrementvar` won't cut it. But that's rare, so I won't cover it here.
Cycle binds
By applying a bit more writing, you can create binds that toggle or cycle between arbitrary states. There are of course limitations, but it should serve decently in most cases.

alias damageoff "con_filter_enable 0; developer 0; bind / damageon" alias damageon "con_filter_enable 2; con_filter_text Damage; developer 1; bind / damageoff" bind / damageon

The above bind will only use 1 key to toggle between two arbitrary states. Specifically, pressing `j` will turn a damage output at the top left of your screen (it's just the damage messages from the console).

As you can see, the whole trick is to make each key press change the binding of the key you just pressed.

You can chain these binds of course if necessary. All you need to do is make sure each key press re-binds the key to what you want it to do the next time you press it. Remember to use aliases since the CS:GO console doesn't like nested quotes.
Adding sounds and console output
You can add sounds to binds by using the `play` and `playvol` console commands. These play a sound and play it at a specific volume respectively. I recommend only using `playvol` even if you don't want to change the volume, because it'll be easier to modify in the future and it'll make your script easier to understand.

Additionally, you can echo strings of text to the console, which can serve as feedback, in case you need to know what state your toggle or bind is in, or if it even activated at all.

Here's the previous section's bind with the above two tricks added:

alias damageoff "con_filter_enable 0; developer 0; bind / damageon; playvol ui\menu_invalid 0.7; echo Damage display off" alias damageon "con_filter_enable 2; con_filter_text Damage; developer 1; bind / damageoff; playvol ui\menu_accept 0.7; echo Damage display on" bind / damageon

Now, whenever you press `j`, it will do the toggle, play a sound to let you know the command string actually ran and output a message to the console informing you in what state the toggle is in, so you don't have to wonder.

You can find sounds to use by using `soundlist` in combination with `con_filter_text` and `con_filter_enable` to narrow down the list to what you may be interested in.
Addendum
A nice couple of commands to help you with figuring out your binds are:

key_findbinding
and
key_listboundkeys

which both do what their name says. Very handy when you don't know what's unbound and free and what mess you've made by fiddling with binds!

Also, if you want to ask a question on why your binds aren't working or how to make a complex setup work, please use pastebin[pastebin.com] and paste the contents of your .cfg script there and the link to your paste in your question. It's much easier to understand what the problem is that way.
39 Comments
𓅃 スノ 𓅃 Mar 7, 2023 @ 10:27am 
can I put a toggler in this as well?
I want to church with mouse 4 that is easy but.
What if i want to quick kinfe switch and gun siwtch
Johny6700 Feb 16, 2021 @ 8:53pm 
How do i add alt as a modifier for mouse wheel down jump?
mechalynx  [author] Feb 13, 2021 @ 6:05am 
<3
Crokobos Feb 9, 2021 @ 7:05am 
Thanks for even answering! Your dedication and helpfullness gave you the reward.
I'l try dissecting the script like you said.
mechalynx  [author] Feb 9, 2021 @ 4:24am 
Also thanks for the award, whoever it was (I don't think I can see the name) <3
mechalynx  [author] Feb 9, 2021 @ 4:21am 
Sorry I haven't been on steam at all for a week. I hate to disappoint you but I can't test this currently to see what might be wrong and it seems things have changed since I last played csgo so I'm afraid I can't help you. It probably isn't much help but perhaps if you break it down into parts and try one thing at a time, it might reveal what's causing the problem. Good luck with it and sorry again.
Crokobos Feb 2, 2021 @ 4:51am 
I want alt to be a modifier, so I can use the main action buttons for start of round advice messages when I hold it. The current behaviour even after rewrites is a somewhat functioning normal weapon selection and normal wasd, but no intended functionality. Instead it throws me the 'how to use this command' error. I'm sure I correctly used bind within quotes so I'm wrong or this is a nesting issue, causing only part of the bind command to be recognised.
mechalynx  [author] Feb 1, 2021 @ 4:23am 
I actually just saw this sorry and I have to go to bed. It's been a long time since I've seen a cfg script so I don't see anything wrong at a cursory glace. Can you mention what you want to happen but doesn't?
Crokobos Jan 30, 2021 @ 12:15pm 
Thanks for making this guide! As is usual, the first thing I tried doing here is using alt to acces 8 different say_team commands. Of course i hit the 255 character console limit, which gives me two options: either wrap it in a cfg to run it once, or ask this thread whats wrong with my nested alias code. Good luck.

alias +MALTtop "bind q say_team We should rush B; bind w say_team We should rush MID; bind e say_team We should rush A; +quickinv" ;
alias -MALTtop "bind q lastinv; bind w +forward; bind e +use; -quickinv" ;
alias +MALTbottom "bind a say_team We should hold B; bind s say_team We should hold MID; bind d say_team We should hold A" ;
alias -MALTbottom "bind a +moveleft; bind s +back; bind d +moveright" ;
alias +MALTrest "bind r say_team We should split up; bind f say_team We should stay in SPAWN" ;
alias -MALTrest "bind r +reload; bind f buymenu" ;
bind alt "+MALTtop; +MALTbottom; +MALTrest"
IAMSOLAME Dec 6, 2018 @ 11:37am 
ya thanks i found it << bind "DEL" "toggle cl_righthand 0 1"

but thanks anyway for the fast reply =)