SixL client API / system / KeysMp
Interface: KeysMp
The keyboard: handlers for key presses and releases, and the current key state.
Remarks
Key codes are Windows virtual-key codes, as the game window's keyboard reports them: 0x45 is E, 0x0D is Enter, 0x20 is Space. Keys are read from the game window, so they work only while it has the keyboard.
Example
mp.keys.bind(0x45, true, () => mp.console.logInfo('E pressed'));
Methods
bind()
bind(keyCode,keyHold,handler):void
Calls a handler when a key goes down or up.
Parameters
keyCode
number
The virtual-key code, e.g. 0x45 for E.
keyHold
boolean
true calls the handler when the key goes down; false when it comes up.
handler
() => void
Called with no arguments. An error in it is logged; the other handlers still run.
Returns
void
Remarks
A key that is held down does not call a keyHold = true handler again (no auto-repeat). Several handlers may be bound to one key.
Example
mp.keys.bind(0x47, false, () => mp.console.logInfo('G released'));
isDown()
isDown(keyCode):boolean
Whether a key is down now.
Parameters
keyCode
number
The virtual-key code.
Returns
boolean
True while the key is held down. A key not yet seen since the start is up.
Example
if (mp.keys.isDown(0x10)) { }
isUp()
isUp(keyCode):boolean
Whether a key is up now: the opposite of isDown.
Parameters
keyCode
number
The virtual-key code.
Returns
boolean
True while the key is not held down.
Example
if (mp.keys.isUp(0x10)) { }
unbind()
unbind(keyCode,keyHold,handler?):void
Removes handlers bound with bind.
Parameters
keyCode
number
The virtual-key code.
keyHold
boolean
The same flag as the one the handler was bound with.
handler?
() => void
The handler to remove. Optional: when left out, every handler of that key and flag is removed.
Returns
void
Example
mp.keys.unbind(0x45, true, onE);