Key::bind: Difference between revisions

From RAGE Multiplayer Wiki
mNo edit summary
 
(10 intermediate revisions by 6 users not shown)
Line 1: Line 1:
This function binds the key .
{{ClientsideJsFunction}}
 
== Description ==
This function binds the key.


==Parameters==
==Parameters==
* '''keycode''' - code of [https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731 key] (Hexadecimal).
* '''keycode''' - hexadecimal code of [https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731 key].
* '''keyhold''' - call function as long as key is held pressed? (Bool)
* '''keydown/keyup''' - true trigges on keydown, false triggers on keyup (bool)
* '''handler''' - function-handler.
* '''handler''' - function-handler.


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


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

Latest revision as of 12:48, 15 January 2025

Client-Side
Function

 JavaScript



Description

This function binds the key.

Parameters

  • keycode - hexadecimal code of key.
  • keydown/keyup - true trigges on keydown, false triggers on keyup (bool)
  • handler - function-handler.

Example

This example calling server event.

/** binds F2 to this inline arrow function */
mp.keys.bind(0x71, true, () => {
	mp.gui.chat.push("F2 was pressed")
});

See also