Squirrel/Client/Functions/Controls/BindKey

From Liberty Unleashed Wiki
(Difference between revisions)
Jump to: navigation, search
(New page: {{Squirrel/Title|BindKey}} This function binds a key to a handler function, which will be called when the player presses the key. == Syntax == <code>bool BindKey( int key, int state, cl...)
 
m
Line 23: Line 23:
 
{
 
{
 
     BindKey( 'H', BINDTYPE_DOWN, HalloThere, 123 );
 
     BindKey( 'H', BINDTYPE_DOWN, HalloThere, 123 );
 +
   
 +
    return 1;
 
}
 
}
  

Revision as of 14:45, 11 April 2010

Home   |   Squirrel Scripting   |   Server Functions   |   Server Events   |   Client Functions   |   Client Events


This function binds a key to a handler function, which will be called when the player presses the key.

Syntax

  1. bool BindKey( int key, int state, closure func, [ args... ] )
  1. bool BindKey( int key, int state, string func, [ args... ] )

Arguments

  • key - This is the key to be bound. For keys 'A'-'Z' and '0'-'9' this value will be the ascii code of the character. For special keys, check a list here
  • state - The bind type, either BINDTYPE_DOWN (triggered when the key is pressed down) or BINDTYPE_UP (triggered when the key is released)
  • func - Either a pointer to the handler function or the name of the function as a string
  • args - Any additional arguments you wish to pass to the handler function

Example

This example will print "Hallo there! 123" to the chatbox when the player presses the H key down.

  1.  
  2. function onScriptLoad()
  3. {
  4. BindKey( 'H', BINDTYPE_DOWN, HalloThere, 123 );
  5. return 1;
  6. }
  7.  
  8. function HalloThere( somenumber )
  9. {
  10. Message( "Hallo there! " + somenumber );
  11. }
  12.  

Notes

The function Message and call onScriptLoad were used in in this example. More info about them in the corresponding pages.

Related Functions

Personal tools
Namespaces

Variants
Actions
Navigation
scripting
Toolbox