Squirrel/Client/Functions/Controls/BindKey
From Liberty Unleashed Wiki
(Difference between revisions)
(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
This function binds a key to a handler function, which will be called when the player presses the key.
Syntax
bool BindKey( int key, int state, closure func, [ args... ] )
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.
function onScriptLoad() { BindKey( 'H', BINDTYPE_DOWN, HalloThere, 123 ); return 1; } function HalloThere( somenumber ) { Message( "Hallo there! " + somenumber ); }
Notes
The function Message and call onScriptLoad were used in in this example. More info about them in the corresponding pages.