bindKey: Difference between revisions

From GTA Connected
Jump to navigation Jump to search
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 3: Line 3:
|type = function
|type = function
|name = bindKey
|name = bindKey
|usage = bind a handler to be called when a specific key is pressed or released
|usage = bind a handler to be called when a specific key is pressed, released, or either pressed/released
|parameters = int keyCode, int keyState, function callback
|parameters = int keyCode, int keyState, function handler
|parameter1 = int keyCode The key code to bind the event for.
|parameter1 = int keyCode The key code to bind the event for.
|parameter2 = int keyState The key state to bind the event for.
|parameter2 = int keyState The key state to bind the event for. KEYSTATE_DOWN, KEYSTATE_UP, or KEYSTATE_BOTH.
|parameter3 = function callback The scripting function to call when the event occurs.
|parameter3 = function handler The scripting function to call when the specified key is pressed, released, or either pressed/released.
|callbackParametersSS = KeyEvent event, Client client
|callback3SyntaxSS = KeyEvent event, Client client
|callbackParametersCS = KeyEvent event
|callback3ParameterSS1 = KeyEvent event The KeyEvent object for the event.
|callback3ParameterSS2 = Client client The Client who triggered the key event.
|callback3SyntaxCS = KeyEvent event
|callback3ParameterCS1 = KeyEvent event The KeyEvent object for the event.
|return1 = void
|return1 = void
|returnFail1 = void
|returnFail1 = void

Latest revision as of 23:49, 20 April 2021

Function Server and Client icon-iii.png icon-vc.png icon-sa.png icon-iv.png Online and Offline

Available since Server 1.0.0, Client 1.0.0

void bindKey(int keyCode, int keyState, function handler)

The bindKey function is used to bind a handler to be called when a specific key is pressed, released, or either pressed/released.

Parameters

1) int keyCode The key code to bind the event for.
2) int keyState The key state to bind the event for. KEYSTATE_DOWN, KEYSTATE_UP, or KEYSTATE_BOTH.
3) function handler The scripting function to call when the specified key is pressed, released, or either pressed/released.

Return

void This function doesn't return a value.

Callbacks

Server-Side Callbacks

function handler(KeyEvent event, Client client)

1) KeyEvent event The KeyEvent object for the event.
2) Client client The Client who triggered the key event.

Client-Side Callbacks

function handler(KeyEvent event)

1) KeyEvent event The KeyEvent object for the event.

Notes

Examples

Example 1 - JavaScript:

bindKey(SDLK_g, KEYSTATE_DOWN, function(e) {

   console.log("g key pressed down.");

})

Compatibility

There isn't any compatibility information for this function.

Related

Server Related

icon-iii.png icon-vc.png icon-sa.png icon-iv.png bindKey
icon-iii.png icon-vc.png icon-sa.png icon-iv.png unbindAllKeys
icon-iii.png icon-vc.png icon-sa.png icon-iv.png unbindKey


Client Related

icon-iii.png icon-vc.png icon-sa.png icon-iv.png bindKey
icon-iii.png icon-vc.png icon-sa.png icon-iv.png isKeyDown
icon-iii.png icon-vc.png icon-sa.png icon-iv.png isScancodePressed
icon-iii.png icon-vc.png icon-sa.png icon-iv.png unbindAllKeys
icon-iii.png icon-vc.png icon-sa.png icon-iv.png unbindKey