BindKey: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 9: Line 9:
*'''key:''' The key you wish to bind to the command. See [[Key names]] for a list of possible keys.
*'''key:''' The key you wish to bind to the command. See [[Key names]] for a list of possible keys.
*'''command:''' The command that will be triggered when the player's key is pressed. See [[Control names]] for a list of GTA keys that can be used.
*'''command:''' The command that will be triggered when the player's key is pressed. See [[Control names]] for a list of GTA keys that can be used.
Note: The 'key' variable can be a control instead, if this is so, the command will be called everytime that key is pressed or released, depending on 'keyState'.


===Optional Arguments===
===Optional Arguments===
*'''keyState:''' A string containing the word "up" or "down" determining when the binded command will be called.
*'''keyState:''' A string containing the word "up" or "down" determining when the binded command will be called.
*'''arguments:''' Any arguments you may want to pass to the command handler.
*'''arguments:''' Any arguments you may want to pass to the command handler.
Note: 'keyState' will default to "down" if not specified.


==Example==   
==Example==   

Revision as of 22:56, 11 July 2006

Binds a player's key to a console command, which will be triggered when the key is pressed.

Syntax

bindKey ( player thePlayer, string key, [ string keyState ], string command, [ string arguments ] ) 

Required Arguments

  • thePlayer: The player you wish to bind the key of.
  • key: The key you wish to bind to the command. See Key names for a list of possible keys.
  • command: The command that will be triggered when the player's key is pressed. See Control names for a list of GTA keys that can be used.

Note: The 'key' variable can be a control instead, if this is so, the command will be called everytime that key is pressed or released, depending on 'keyState'.

Optional Arguments

  • keyState: A string containing the word "up" or "down" determining when the binded command will be called.
  • arguments: Any arguments you may want to pass to the command handler.

Note: 'keyState' will default to "down" if not specified.

Example

This function will bind a player's 'F1' key to a command.

addCommandHandler ( "bindmekeysplz", "bindtehkeys" )
function bindtehkeys ( source )
  bindKey ( source, "F1", "down", "keydown" ) -- bind the player's F1 down key
  bindKey ( source, "F1", "up", "keyup" ) -- bind the player's F1 up key
end

addCommandHandler ( "keydown", "keydown" )
function keydown ( source )
  outputChatBox ( getClientName ( source ).." pressed the F1 key" )
end

addCommandHandler ( "keyup", "keyup" )
function keyup ( source )
  outputChatBox ( getClientName ( source ).." let go of the F1 key" )
end

See Also