Keys::unbind: Difference between revisions

From RAGE Multiplayer Wiki
(Add mp.keys.unbind)
 
mNo edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 11: Line 11:


==Example==
==Example==
<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">
function checkKeyPressing() {
function handler() {
    mp.gui.chat.push( "Pressing F2" );
mp.gui.chat.push("F2 was pressed");
}
}


function toggleTestMessageBind ( bool ) {
function toggle_keybind(state) {
    if ( bool )
state
        mp.keys.bind( 0x71, true, checkKeyPressing ); //bind testMessage to F2
? mp.keys.bind(0x71, true, handler); /** binds F2 to the handler fn */
    else
: mp.keys.unbind(0x71, true, handler);  /** unbinds the handler from F2 key */
        mp.keys.unbind( 0x71, true, checkKeyPressing );  //unbind it
}
}
</syntaxhighlight>
</syntaxhighlight>
</div>


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

Latest revision as of 12:46, 15 January 2025

This function unbinds the key.

Required Arguments

  • keycode - Code of key (Hexadecimal).
  • keyhold - Unbind the binds with keyhold-value.

Optional Arguments

  • handler - Only unbind this handler.

Keycodes can be found here

Example

Client-Side
function handler() {
	mp.gui.chat.push("F2 was pressed");
}

function toggle_keybind(state) {
	state
		? mp.keys.bind(0x71, true, handler); /** binds F2 to the handler fn */
		: mp.keys.unbind(0x71, true, handler);  /** unbinds the handler from F2 key */
}

See also