Detect Keydown and Key release!

● ARCHIVED · READ-ONLY
Started by AaronTrip 8 posts View original ↗
  1. Hi, Im pretty new to RPG maker MV and im a little stuck right now.
    Basically what I want to do is for the game be able to detect when the keys J, K and L are being pressed down, and also when they are released. The Mechanic for my game is color changing so in short what I want is when a key is being held for screen to tint, and when its released the screen will to go back to normal. Any info helps! Thanks.
  2. Thank you for the reply! This looks like a plugin that supports touch screen commands! Im looking to use the in game tint function on keyboard commands!

    Unless the plugin allows me to re-map its feature to keys?
  3. The engine only recognizes a certain amount of keys by default. You can look into the spoiler to see which keys it recognizes with just the base code:
    Spoiler
    Code:
    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
    };

    Fortunately, it's easy to add more keys that it recognizes.

    1.) We first check a table to see what code corresponds to J, K, and L. The corresponding number codes are 74, 75, and 76.

    2.) Then we can add those keys to the mapping that the engine recognizes:
    Code:
    Input.keyMapper[74] = 'J';
    Input.keyMapper[75] = 'K';
    Input.keyMapper[76] = 'L';
    ^^ You can add this code as a new "plugin".

    3.) Now, inside a parallel event (it can be on the map, or a Common Event), you can check if these keys are pressed down.

    You can use the Conditional Branch command with the script option. The following script checks are relevant for you.

    Code:
    Input.isTriggered('J')
    // This is true if J was just pressed, false if J was not just pressed

    Code:
    Input.isPressed('K')
    // This is true if K is currently pressed, false if K is not currently pressed

    Code:
    Input.isLongPressed('L')
    // This is true if L has been pressed for longer than 24 frames, false if L has not been pressed for longer than 24 frames

    If you want to check the opposite, i.e. check if a button is NOT pressed, just put an exclamation mark at the front.
    Code:
    !Input.isLongPressed('J')

    4.) Construct your event. Remember that parallel events run every single frame, so you want to use some switches so that you don't lag your game.

    Something like (these are pseudo-commands, you have to translate it to event commands)

    Code:
    Conditional Branch: If the Tint Switch is OFF:
        Conditional Branch: If 'K' is Long Pressed:
            Tint the screen
            Turn ON the Tint Switch
    Conditional Branch: If the Tint Switch is ON:
        Conditional Branch: If 'K' is NOT Long Pressed:
            Tint the screen back to normal
            Turn OFF the Tint Switch
    You'll have to test it and tweak it, maybe add some Wait commands, but that's the idea.
  4. Awesome info! thank you! so when adding those key mappers as a plugin do i just have to copy that code into a js file and put it in the plugins folder? then just turn it on?
  5. AaronTrip said:
    Awesome info! thank you! so when adding those key mappers as a plugin do i just have to copy that code into a js file and put it in the plugins folder? then just turn it on?
    Exactly.
  6. awesome, so I've got it working that when you press the button down it will tint the screen, and when you release it will go back to normal. I've noticed now though that if the button is held down for longer than a few seconds, it still goes back to normal no matter what. Im wondering if there is a way to get the screen to just wait until you release the button?
  7. actually, i think i figured it out, so far at least hahah. Thanks again!