Key::bind: Difference between revisions

From RAGE Multiplayer Wiki
Line 8: Line 8:
==Example==
==Example==
This example calling server event.
This example calling server event.
<div class="header" style="background-color: #AE4040; color: #FFFFFF; border: 2px solid #408DAE;">
{{ClientSide}}
<div style="margin: 10px 10px 10px 10px;"><b>Client-Side</b></div>
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
// 0x71 is the F2 key code
// 0x71 is the F2 key code
Line 17: Line 16:
});
});
</syntaxhighlight>
</syntaxhighlight>
</div>


==See also==
==See also==
{{KeyBinding_function_c}}
{{KeyBinding_function_c}}

Revision as of 23:29, 4 April 2018

This function binds the key .

Parameters

  • keycode - hexadecimal code of key.
  • keyhold - call function as long as key is held pressed? (Bool)
  • handler - function-handler.

Example

This example calling server event.

Client-Side
// 0x71 is the F2 key code
mp.keys.bind(0x71, true, function() {
    mp.events.callRemote('keypress:F2'); // Calling server event "keypress:F2"
    mp.gui.chat.push('F2 key is pressed. This message will be shown until you release the key, because "keyhold" is true.');
});

See also