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