Key::bind: Difference between revisions

From RAGE Multiplayer Wiki
(Changed word "Int" to "Number" for semantic reasons, as this is JavaScript.)
m (Replace integer keycodes with hexadecimal keycodes)
Line 2: Line 2:


==Parameters==
==Parameters==
* '''keycode''' - code of key (Number).
* '''keycode''' - code of key (Hexadecimal).
* '''keyhold''' - call function as long as key is held pressed? (Bool)
* '''keyhold''' - call function as long as key is held pressed? (Bool)
* '''handler''' - function-handler.
* '''handler''' - function-handler.
[https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731 Keycodes can be found here]


==Example==
==Example==
Line 11: Line 13:
<div style="margin: 10px 10px 10px 10px;"><b>Client-Side</b></div>
<div style="margin: 10px 10px 10px 10px;"><b>Client-Side</b></div>
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
// 113 is the F2 key code
// 0x71 is the F2 key code
mp.keys.bind(113, true, function() {
mp.keys.bind(0x71, true, function() {
     mp.events.callRemote('keypress:F2'); // Calling server event "keypress:F2"
     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.');
     mp.gui.chat.push('F2 key is pressed. This message will be shown until you release the key, because "keyhold" is true.');

Revision as of 17:46, 30 November 2017

This function binds the key .

Parameters

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

Keycodes can be found here

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