Xyphien Forums

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

Check for keyboard input.

LTN Games

Master Mind
Resource Team
Xy$
0.01
This should do the trick
JavaScript:
Input.isKeyTriggered(keycode)
Input.isKeyPressed(keycode)
Keycodes are here: https://keycode.info/
MV also has a keymap so you can use words like 'left', 'right' etc
JavaScript:
Input.keyMapper = {
    9: 'tab',       // tab
    13: 'ok',       // enter
    16: 'shift',    // shift
    17: 'control',  // control
    18: 'control',  // alt
    27: 'escape',   // escape
    32: 'ok',       // space
    33: 'pageup',   // pageup
    34: 'pagedown', // pagedown
    37: 'left',     // left arrow
    38: 'up',       // up arrow
    39: 'right',    // right arrow
    40: 'down',     // down arrow
    45: 'escape',   // insert
    81: 'pageup',   // Q
    87: 'pagedown', // W
    88: 'escape',   // X
    90: 'ok',       // Z
    96: 'escape',   // numpad 0
    98: 'down',     // numpad 2
    100: 'left',    // numpad 4
    102: 'right',   // numpad 6
    104: 'up',      // numpad 8
    120: 'debug'    // F9
};
 

CT_Bolt

Global Moderator
Staff member
Resource Team
Xy$
0.12
This should do the trick
JavaScript:
Input.isKeyTriggered(keycode)
Input.isKeyPressed(keycode)
Keycodes are here: https://keycode.info/
MV also has a keymap so you can use words like 'left', 'right' etc
JavaScript:
Input.keyMapper = {
    9: 'tab',       // tab
    13: 'ok',       // enter
    16: 'shift',    // shift
    17: 'control',  // control
    18: 'control',  // alt
    27: 'escape',   // escape
    32: 'ok',       // space
    33: 'pageup',   // pageup
    34: 'pagedown', // pagedown
    37: 'left',     // left arrow
    38: 'up',       // up arrow
    39: 'right',    // right arrow
    40: 'down',     // down arrow
    45: 'escape',   // insert
    81: 'pageup',   // Q
    87: 'pagedown', // W
    88: 'escape',   // X
    90: 'ok',       // Z
    96: 'escape',   // numpad 0
    98: 'down',     // numpad 2
    100: 'left',    // numpad 4
    102: 'right',   // numpad 6
    104: 'up',      // numpad 8
    120: 'debug'    // F9
};
What I'm seeing (& works for me) is just a slight bit different like this...
7986
Input.isTriggered('ok');
...Without the "Key" before "Triggered", also does not seem to take keycodes... only strings for keys...
(or at least didn't work for me like that, maybe that does work & I missed an update though or something?)

isTriggered
  • isTriggered(keyName: string): boolean
  • Checks whether a key is just pressed.
    staticmethod
    isTriggered
    Parameters
    • keyName: string
      The mapped name of the key
  • Returns boolean
    True if the key is triggered
Input Documentation (The static class that handles input data from the keyboard and gamepads):
The only place I see keycode used is Input._onKeyDown & Input._onKeyUp, see docs here: (They are only binded to the class and pass along the name/state of buttons, not a public method that returns something).
Which those get passed a keyboard event that does contain a keycode.
... but without an overwrite/alias to those functions we're stuck with using that only button names provided by the mapper.
Sadly the Input Object never actually gets passed the keycode only the name defined by the keyMapper.

Maybe I just missed something though?
I could be totally wrong here, and what you mentioned might work, but it crashed when I tried what you had. (perplexed)(cool)
 
Last edited:

CynicSyndrome

Towns Guard
Xy$
0.36
Thank you, I was able to write my own key mapping plugin that is working now. I was not able to change "shift" into "run" but i think I understand why.
 
Top