This article's documentation is for the "GoldSrc" engine. Click here for more information.
This article's documentation is for anything that uses the Source engine. Click here for more information.
This article's documentation is for Source 2. Click here for more information.

bind

From Valve Developer Community
Jump to: navigation, search

bind is a console command available in all GoldSrc GoldSrcSource Source and Source 2 Source 2 games.

English (en)
Edit

It is used to bind a key to one or several other commands. Typically, when keys are bound, the corresponding bind command is stored in config.cfg, which is ran when the engine starts, leading to binds staying active between sessions, unless config.cfg is set to read-only.

Syntax

Basic Syntax

The basic syntax for the command is as follows:

bind <key> [command]

For example, after running bind 1 slot1, pressing 1 would execute the command slot1. Additionally, binding a key to a semicolon-separated list of commands in quotation marks would cause all commands to be executed, because everything within quotation marks is interpreted as a single argument. After running bind mouse1 "slot1; unbind mouse1", then pressing mouse1, slot1 would be run, followed by unbind mouse1.

+/- Commands

If the first character in the command/string that the key is bound to is +, then after releasing the key, the same string of commands is executed, except the first character is replaced with -. For example, running bind w +forward will cause +forward to be run when w is pressed, then -forward to be run when w is unpressed. Consequently, there are some cases where the result of pressing a key are different from what is intuitive. Running bind w "+forward; +attack" will cause +forward;+attack to be run when w is pressed, but causes -forward;+attack to be run when w is unpressed, causing +attack to be run, rather than -attack. The alias command can be used in conjunction with bind to yield different results. To make the W key instead run +forward; +attack when pressed, and run -forward; -attack when unpressed, the following commands can be used:

alias +w_pressed "+forward; +attack"
alias -w_pressed "-forward; -attack"
bind w +w_pressed

Special Keys

Note.pngNote:Some gamepads button (such as A_BUTTON, but not joyX) may be disabled or become non-functional in favor of Steam Input, if the Gamepad UI were enabled (tested on Half-Life 2 Half-Life 2).
System Commands, Modifier Keys, Other
Bind name Key
f1-12 Function key
F1 to F12
escape Esc (Escape)
tab Tab Tabulator
capslock Caps Lock
shift Shift (Left side)
rshift Shift (Right side)
ctrl Ctrl (Left side)
rctrl Ctrl (Right side)
alt Alt (Left side)
ralt Alt (Right side)
space Spacebar
backspace ← Backspace
enter Enter
semicolon Semicolon (;)
lwin Win (Left side)
rwin Win (Right side)
apps Menu
numlock Num Lock
scrolllock Scroll Lock
Navigation Keys
Bind name Key
uparrow Up Arrow
downarrow Down Arrow
leftarrow Left Arrow
rightarrow Right Arrow
ins Insert
del Delete
pgdn Page Down
pgup Page Up
home Home
end End
pause Pause (or Pause/Break)
Number Pad
Bind name Key
kp_end Keypad 1
kp_downarrow Keypad 2
kp_pgdn Keypad 3
kp_leftarrow Keypad 4
kp_5 Keypad 5
kp_rightarrow Keypad 6
kp_home Keypad 7
kp_uparrow Keypad 8
kp_pgup Keypad 9
kp_enter Keypad Enter
kp_ins Keypad 0
kp_del Keypad .
kp_slash Keypad /
kp_multiply Keypad *
kp_minus Keypad -
kp_plus Keypad +
Mouse Buttons
Bind name Key
mwheeldown Mouse - Scroll Down
mwheelup Mouse - Scroll Up
mouse1 LMB (Mouse - Left click)
mouse2 RMB (Mouse - Right click)
mouse3 MMB (Mouse - Middle/Wheel click)
mouse4 MOUSE4 (Mouse - Page Back)
mouse5 MOUSE4 (Mouse - Page Forward)
Gamepad Buttons (Xbox 360/PlayStation/Nintendo Switch)
Bind name Key
Z AXIS POS Xbox 360 LT (left trigger) button
Z AXIS NEG Xbox 360 RT (right trigger) button
joy1 / A_BUTTON Xbox 360 A button button
PlayStation X (Cross) button (Cross) button
joy2 / B_BUTTON Xbox 360 B button button
PlayStation O (Circle) button (Circle) button
joy3 / X_BUTTON Xbox 360 X button button
PlayStation □ (Square) button (Square) button
joy4 / Y_BUTTON Xbox 360 Y button button
PlayStation Δ (Triangle) button (Triangle) button
joy5 / L_SHOULDER Xbox 360 Left bumper button (left bumper) button
PlayStation L1 button
joy6 / R_SHOULDER Xbox 360 Right bumper button (right bumper) button
PlayStation R1 button
joy7 / BACK Xbox 360 ◄ Back button (Back) button
Xbox One View button
PlayStation L2 (left trigger) button
joy8 / START Xbox 360 ► Start button (Start) button
Xbox One Menu button
PlayStation R2 (right trigger) button
joy9 / STICK1 Xbox 360 LS button (Left stick) button
PlayStation Select/Share/Create button
joy10 / STICK2 Xbox 360 RS button (Right stick) button
PlayStation Start/Options button
joy11 PlayStation L3 button
joy12 PlayStation R3 button
joy13 PlayStation button
joy14 PlayStation (PS4/PS5 only) - Touchpad
joy15-32 Other joystick & gamepad buttons.
aux1-32 Legacy. Maps directly to joy1-32.
pov_up D-Pad Up
pov_right D-Pad Right
pov_down D-Pad Down
pov_left D-Pad Left

Related console commands

binds_per_command

Set the maximum number of binds per command when on console. Does not apply to desktop.

Syntax:

binds_per_command <number>

BindToggle

A convenient command for toggling a CVar on or off by pressing a key. Functionally identical to bind <key> "incrementvar <CVar> 0 1 1".

Syntax:

BindToggle <key> <cvar>

If you wanted your p key to turn sv_cheats on or off, you would type BindToggle p sv_cheats.

bind_mac

Functions identically to bind except it only affects macOS macOS users.

unbind

The opposite of bind. Sets a key to do nothing.

Syntax:

unbind <key>

To make your left click do nothing, you would type unbind MOUSE1.

unbind_mac

Functions identically to unbind except it only affects macOS macOS users.

unbindall

The infamous command that unbinds all the keys.

Tip.pngTip:If you do this command (or you're a poor sap that got tricked), you can reset to default bindings in the Options menu. Keyboard, Use Defaults.

key_listboundkeys

Lists all keys that are bound to something, and what they are bound to.

Example input and output from Half-Life 2:


] key_listboundkeys 
"6" = "slot6"
"1" = "slot1"
"a" = "+moveleft"
"2" = "slot2"
"c" = "impulse 50"
"3" = "slot3"
"d" = "+moveright"
"4" = "slot4"
"e" = "+use"
"5" = "slot5"
"f" = "impulse 100"
"g" = "phys_swap"
"q" = "lastinv"
"w" = "+forward"
"r" = "+reload"
"z" = "+zoom"
"s" = "+back"
"`" = "toggleconsole"
"SPACE" = "+jump"
"NUMLOCK" = "pause"
"ESCAPE" = "cancelselect"
"SHIFT" = "+speed"
"CTRL" = "+duck"
"ALT" = "+walk"
"F5" = "jpeg"
"F6" = "save quick"
"F9" = "load quick"
"MOUSE1" = "+attack"
"MWHEELDOWN" = "invnext"
"MOUSE2" = "+attack2"
"MWHEELUP" = "invprev"

key_findbinding

Searches through the list of bound keys and returns the ones that have a given substring in the command field.

Syntax:

key_findbinding <string>

Example input and output from Half-Life 2:

] key_findbinding slot
"1" = "slot1"
"2" = "slot2"
"3" = "slot3"
"4" = "slot4"
"5" = "slot5"
"6" = "slot6"

key_updatelayout

Updates game keyboard layout to current windows keyboard setting. Only works on windows.

This is only useful if your virtual keyboard layout changes in Windows (i.e changing from QWERTY to AZERTY) while the game is running.