Key::bind: Difference between revisions

From RAGE Multiplayer Wiki
(Easy to use Key Finding tool)
mNo edit summary
 
(One intermediate revision by one other user not shown)
Line 2: Line 2:


== Description ==
== Description ==
This function binds the key .
This function binds the key.


==Parameters==
==Parameters==
* '''keycode''' - hexadecimal code of [https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731 key]. (For an easy to use Key finding tool - try [https://keycode.info/ keycode.info])
* '''keycode''' - hexadecimal code of [https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731 key].
* '''keydown/keyup''' - true trigges on keydown, false triggers on keyup (bool)
* '''keydown/keyup''' - true trigges on keydown, false triggers on keyup (bool)
* '''handler''' - function-handler.
* '''handler''' - function-handler.
Line 13: Line 13:


<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.');
});
});
</syntaxhighlight>
</syntaxhighlight>

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