Bind: Difference between revisions
No edit summary |
(Separated Mouse and Gamepad buttons.) |
||
Line 1: | Line 1: | ||
{{langsp|title=bind}} | {{langsp|title=bind}} | ||
{{toc-right}} | {{toc-right}} | ||
'''{{code|bind}}''' is a [[Developer Console|console]] command used to bind a key to one or several other commands. Typically, when keys are bound, the corresponding | '''{{code|bind}}''' is a [[Developer Console|console]] command used to bind a key to one or several other commands. Typically, when keys are bound, the corresponding {{code|bind}} command is stored in {{code|config.cfg}}, which is ran when the engine starts, leading to binds staying active between sessions, unless {{code|config.cfg}} is set to read-only. | ||
==Syntax== | ==Syntax== | ||
Line 9: | Line 9: | ||
The basic syntax for the command is as follows: | The basic syntax for the command is as follows: | ||
{{pre|bind <key> [command]}} | {{pre|bind <key> [command]}} | ||
For example, after running | For example, after running {{code|bind 1 slot1}}, pressing {{key|1}} would execute the command {{code|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 {{code|bind mouse1 "slot1; unbind mouse1"}}, then pressing mouse1, {{code|slot1}} would be run, followed by {{code|unbind mouse1}}. | ||
===+/- Commands=== | ===+/- Commands=== | ||
If the first character in the command/string that the key is bound to is | 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 {{code|bind w +forward}} will cause {{code|+forward}} to be run when {{key|w}} is pressed, then {{code|-forward}} to be run when {{key|w}} is unpressed. Consequently, there are some cases where the result of pressing a key are different from what is intuitive. Running {{code|bind w "+forward; +attack"}} will cause {{code|+forward;+attack}} to be run when {{key|w}} is pressed, but causes {{code|-forward;+attack}} to be run when {{key|w}} is unpressed, causing you to continue attacking. The {{code|[[alias]]}} command can be used in conjunction with {{code|bind}} to yield different results. To make the W key instead run {{code|+forward; +attack}} when pressed, and run {{code|-forward; -attack}} when unpressed, the following commands can be used: | ||
alias +w_pressed "+forward; +attack"<br> | alias +w_pressed "+forward; +attack"<br> | ||
Line 18: | Line 18: | ||
bind w +w_pressed | bind w +w_pressed | ||
Additionally, if the key is bound to a string that starts with a + and matches a [[Developer Console|console]] command exactly, the corresponding minus command will not be executed if the plus command was executed more recently than the minus command. For example, after running | Additionally, if the key is bound to a string that starts with a + and matches a [[Developer Console|console]] command exactly, the corresponding minus command will not be executed if the plus command was executed more recently than the minus command. For example, after running {{code|+forward}}, if {{key|w}} is bound to {{code|+forward}}, unpressing {{key|w}} will not execute the command {{code|-forward}}. However, if {{key|w}} was instead bound to the string "{{code|+forward;slot1}}", unpressing {{key|w}} would result in {{code|-forward;slot1}} being executed, because the string "-forward;slot1" is not a console command. It would then be parsed to execute {{code|-forward}} then {{code|slot1}}. | ||
==Special Keys== | ==Special Keys== | ||
{| class="standard-table" style=float:left | {| class="standard-table" style=float:left | ||
Line 189: | Line 189: | ||
| mouse5 | | mouse5 | ||
| Mouse - Page Forward | | Mouse - Page Forward | ||
|- id="joy1-32 | |} | ||
| joy | {| class="standard-table" style=float:left | ||
|+ Gamepad Buttons ({{360}}/{{ps3}}/{{NS}}) | |||
! Bind name | |||
! Key | |||
|- id="joy1-32" | |||
| joy'''1-32''' | |||
| Joystick & gamepad buttons. | | Joystick & gamepad buttons. | ||
|- id="aux1-32" | |- id="aux1-32" | ||
| aux | | aux'''1-32''' | ||
| Legacy. Maps directly to joy | | Legacy. Maps directly to joy'''1-32'''. | ||
|- id="pov_up" | |||
| pov_up | |||
| D-Pad Up | |||
|- id="pov_right" | |||
| pov_right | |||
| D-Pad Right | |||
|- id="pov_down" | |||
| pov_down | |||
| D-Pad Down | |||
|- id="pov_left" | |||
| pov_down | |||
| D-Pad Left | |||
|} | |} | ||
{{clr}} | {{clr}} | ||
Line 206: | Line 223: | ||
===BindToggle=== | ===BindToggle=== | ||
A convenient command for toggling a [[Cvar]] on or off by pressing a key. Functionally identical to | A convenient command for toggling a [[Cvar]] on or off by pressing a key. Functionally identical to {{code|bind KEY "{{ent|incrementvar}} CVAR 0 1 1"}}. | ||
Syntax: | Syntax: | ||
{{pre|BindToggle KEY CVAR}} | {{pre|BindToggle KEY CVAR}} | ||
If you wanted your '''p''' key to turn {{ent|sv_cheats}} on or off, you would type | If you wanted your '''p''' key to turn {{ent|sv_cheats}} on or off, you would type {{code|BindToggle p sv_cheats}}. | ||
===bind_mac=== | ===bind_mac=== | ||
Functions identically to | Functions identically to {{code|bind}} except it only affects {{mac|4}} users. | ||
===unbind=== | ===unbind=== | ||
The opposite of | The opposite of {{code|bind}}. Sets a key to do nothing. | ||
Syntax: | Syntax: | ||
{{pre|unbind KEY}} | {{pre|unbind KEY}} | ||
To make your left click do nothing, you would type | To make your left click do nothing, you would type {{code|unbind MOUSE1}}. | ||
===unbind_mac=== | ===unbind_mac=== | ||
Functions identically to | Functions identically to {{code|unbind}} except it only affects {{mac|4}} users. | ||
===unbindall=== | ===unbindall=== |
Revision as of 03:49, 27 May 2023


bind is a console command 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 you to continue attacking. 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
Additionally, if the key is bound to a string that starts with a + and matches a console command exactly, the corresponding minus command will not be executed if the plus command was executed more recently than the minus command. For example, after running +forward, if w is bound to +forward, unpressing w will not execute the command -forward. However, if w was instead bound to the string "+forward;slot1", unpressing w would result in -forward;slot1 being executed, because the string "-forward;slot1" is not a console command. It would then be parsed to execute -forward then slot1.
Special Keys
Bind name | Key |
---|---|
f1-12 | F1 to F12 (Top Row) |
escape | "ESC" (Top Left of keyboard) |
tab | Tabulator (Above Capslock) |
capslock | Capslock |
shift | Shift (Below Capslock) |
ctrl | Control (Below Capslock) |
alt | Alt (Left of Spacebar) |
space | Spacebar |
backspace | Backspace (Above Enter) |
enter | Enter |
semicolon | Semicolon (This symbol: ";") |
lwin | Windows Key (Left of Spacebar) |
rwin | Windows Key (Right of Spacebar) |
apps | Menu |
numlock | Numlock |
scrolllock | Scrolllock |
Bind name | Key |
---|---|
uparrow | Up Arrow |
downarrow | Down Arrow |
leftarrow | Left Arrow |
rightarrow | Right Arrow |
ins | Insert (Above arrows) |
del | Delete (Above arrows) |
pgdn | Page Down (Above arrows) |
pgup | Page Up (Above arrows) |
home | Home (Above arrows) |
end | End (Above arrows) |
pause | Pause / Break (Above arrows) |
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 + |
Bind name | Key |
---|---|
mwheeldown | Mouse - Scroll Down |
mwheelup | Mouse - Scroll Up |
mouse1 | Mouse - Left click |
mouse2 | Mouse - Right click |
mouse3 | Mouse - Wheel click |
mouse4 | Mouse - Page Back |
mouse5 | Mouse - Page Forward |
Bind name | Key |
---|---|
joy1-32 | 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_down | 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 MAX
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 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 users.
unbindall
The infamous command that unbinds all the keys.

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.