Key::bind: Difference between revisions
(Add definition for unknown parameter "bool0".) |
(Better example that presents the new "keyhold" boolean parameter.) |
||
| Line 11: | Line 11: | ||
<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 | ||
mp.keys.bind( | mp.keys.bind(113, true, function() { | ||
mp.events.callRemote('keypress: | 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.'); | |||
}); | }); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 19:36, 27 November 2017
This function binds the key .
Parameters
- keycode - code of key (Int).
- keyhold - call function as long as key is held pressed? (Bool)
- handler - function-handler.
Example
This example calling server event.
Client-Side
// 113 is the F2 key code
mp.keys.bind(113, 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.');
});