Squirrel/Client/Functions/Controls/BindKey

From Liberty Unleashed Wiki
(Difference between revisions)
Jump to: navigation, search
m
(Example)
 
Line 22: Line 22:
 
function onScriptLoad()
 
function onScriptLoad()
 
{
 
{
     BindKey( 'H', BINDTYPE_DOWN, HalloThere, 123 );
+
     BindKey( 'H', BINDTYPE_DOWN, "HalloThere", 123 );
 
      
 
      
 
     return 1;
 
     return 1;

Latest revision as of 20:43, 3 March 2013

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.

[edit] Syntax

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

[edit] 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

[edit] 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.  

[edit] Notes

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

[edit] Related Functions

Personal tools
Namespaces

Variants
Actions
Navigation
scripting
Toolbox