Difference between revisions of "Keys::isDown"

From RAGE Multiplayer Wiki
Jump to navigation Jump to search
m
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Returns true if the key specific is pressed. Otherwise, returns false.
+
Function to check if specific key is pressed down.
  
==Parameters==
+
==Syntax==
* '''keycode''' - code of the key (Number).
+
<pre>mp.keys.isDown(keyCode);</pre>
 +
 
 +
===Required Argument===
 +
* '''keyCode''': {{RageType|Number}} - [https://keycode.info code of the key].
 +
 
 +
===Return Value===
 +
* {{RageType|Boolean}} - <code>true</code> if the key specified is pressed, Otherwise <code>false</code>.
  
 
==Example==
 
==Example==
 
An interval that runs every half-second and outputs the state of the F2 key (pressed or not).
 
An interval that runs every half-second and outputs the state of the F2 key (pressed or not).
{{ClientSide}}
+
{{ClientsideCode|
 
<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
 
setInterval(() => {
 
setInterval(() => {
     if (mp.keys.isDown(112) === true) { // 112 is the key code for F2
+
     if (mp.keys.isDown(113) === true) { // 113 is the key code for F2
 
         mp.gui.chat.push('F2 key is pressed!');
 
         mp.gui.chat.push('F2 key is pressed!');
 
     } else {
 
     } else {
Line 16: Line 22:
 
}, 500);
 
}, 500);
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
}}
  
 
==See also==
 
==See also==
{{KeyBinding_function_c}}
+
{{Keys_functions_c}}
 +
 
 +
[[Category:Control]]
 +
[[Category:Client-side Function]]

Latest revision as of 15:57, 14 May 2019

Function to check if specific key is pressed down.

Syntax

mp.keys.isDown(keyCode);

Required Argument

Return Value

  • Boolean - true if the key specified is pressed, Otherwise false.

Example

An interval that runs every half-second and outputs the state of the F2 key (pressed or not).

Client-Side
setInterval(() => {
    if (mp.keys.isDown(113) === true) { // 113 is the key code for F2
        mp.gui.chat.push('F2 key is pressed!');
    } else {
        mp.gui.chat.push('F2 key is not pressed!');
    }
}, 500);

See also