Check for keyboard input.

GO TO ADMIN PANEL > ADD-ONS AND INSTALL ABSTRACT SIDEBAR TO SEE FORUMS AND SIDEBAR

CynicSyndrome

Towns Guard
Joined
Dec 6, 2015
Messages
69
Points
59
Location
Vestal, NY
Can you check for keyboard input with a script but no plugin?

if "key" is pressed

stuff

{else} different stuff
 

LTN Games

Master Mind
Resource Team
Joined
Oct 6, 2015
Messages
2,741
Points
626
Location
In My Heart <3
Website
ltngames.gitlab.io
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
Joined
Nov 12, 2015
Messages
566
Points
248
Website
ctbolt.wordpress.com
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
Joined
Dec 6, 2015
Messages
69
Points
59
Location
Vestal, NY
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