Page tree
Skip to end of metadata
Go to start of metadata

Introduced in



Description:Assigns a command to a key or joystick input. The command has access to the variables Boolean variables _alt and _shift, to indicate whether any modifier keys are pressed, and _value, which contains either the joystick status, or a discrete value (0 or 1) in case of regular keys. If the command returns false (or nothing at all), then both, the original action, as well as the newly defined action, is executed at the same time,

If the command returns true (by making it the last command in the script string), then the original behavior associated with the action (or keystroke) is suppressed, and only the newly defined command is executed.


Syntax:key bindKey command
Return Value:Number - Key index (to use with unBindKey).

Alternative Syntax

Syntax:[key, float, rule, vehicle] bindKey command (V1.30+)
  • key: String or Number - Name of a VBS Key Actions or a DIK KeyCodes (key codes do not work for the extended syntax in V1.50 and below).
  • float: Boolean - Whether to get the float inputs from a joystick (true) or discrete values (0 or 1) from a key (false).
  • rule: Number - When the newly defined command should be executed:
    • 0 (with float true): Constantly, while the button is pressed.
    • 0 (with float false): Once, when the button is pressed
    • 1: Once per value change (either joystick move, or once per button press and release). In V1.50, only works reliably, if float is set to true.
    • 2: Constantly (once per simulation step). If used with keyboard input, _value returns 1, while the button is pressed, otherwise 0 is returned. For joystick input, the current float value is returned.
  • vehicle: String - Event is only fired, if the player is inside a vehicle of the specified type (optional).
  • command: String or Code - Script code to run (see description for details).
Return Value:Number - Key index (to use with unBindKey).


Disarms the player, as they step forward:
"MoveForward" bindKey "removeAllWeapons player"
Disarms the player, as they press the up-arrow key:
0xC8 bindKey "removeAllWeapons player"
Suppresses the inventory command, and display a message instead:
["Gear",false,0] bindKey "hint 'no inventory'; true"

Additional Information

See also: bindKeyEx, actionKeysNames, unBindKey, isKeyPressed, inputAction, ctrlSetEventHandler, displaySetEventHandler


The command may not work while dialogs are open. If you need to capture keystrokes while a dialog is open you should use ctrlSetEventHandler or displaySetEventHandler.

Posted on 19:43, 15 July 2009 (CEST)
General Barron
"If the command returns true, then the keystroke will be intercepted and will not be processed as a normal key stroke." This works for all actions EXCEPT movement & fire commands. To block movement keys (such as "moveForward") can use the setDisableAnimationMove command instead.

Posted on 11:57, 18 January 2010 (CET)
At least as of VBS2 1.23, it is not possible to provide this command with parameter of data type 'command: Code'. Only 'command: String' is accepted.