[Solved] Is there a simple way to unbind (disable) the "X" and "Z" keys?

I don't want to use Z/X for input. After some searching, I couldn't find an easy way to do this.

I'm using Yanfly's ButtonCommonEvents plugin, so one of the things I tried was to bind Z and X to an empty common event - but pressing these keys seem to be unchanged in the game (I made sure to "switch" them on too before trying). They still operate as "OK" and "Cancel".

Before I go hacking this ungracefully into the code, I thought I'd ask if there's an easy way to simply disable the X and Z keys. Thanks 🙂
Yep sure is 🙂
Spoiler: Old Info, See below
Most simple way is to comment out or remove the lines from the Input.keyMapper 😉
Original code is in rpg_core.js but best not to change directly. Place code in a plugin and add via the plugin manager. Attached is such plugin for convenience 😉
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
};

Edit #2:
New "remove keys" plugin created. See last post.
[Delete please]
Yep sure is 🙂
Most simple way is to comment out or remove the lines from the Input.keyMapper 😉
Original code is in rpg_core.js but best not to change directly. Place code in a plugin and add via the plugin manager. Attached is such plugin for convenience 😉
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
};

OK, This is weird, but it doesn't work. I commented them out, restarted the game, and Z/X still function as usual. Huh?
OK, This is weird, but it doesn't work. I commented them out, restarted the game, and Z/X still function as usual. Huh?
Spoiler: Old Info, See below
Hmm... does this demo work as needed?
No XZ Keys Demo: Click here to View
@Oatilis
Edit/Update:
Just try this actually 😉
Code:
Input.keyMapper[88] = null;Input.keyMapper[90] = null;

Place as a plugin at the very bottom of the list 🙂
1587077456836.png

Edit #2:
New "remove keys" plugin created. See last post. 😉
ct_bolt: Hi, I tried your No XZ Key plugin and it works great.

But I also tried the first way and it works as well. For my needs, I swapped Z for E and disabled X.
ct_bolt: Hi, I tried your No XZ Key plugin and it works great.
Thanks for testing and the feedback, much appreciated.

Made a plugin for all the keys now on the list 😉
1587082538038.png

Spoiler
1587082050210.png
Thanks for testing and the feedback, much appreciated.

Made a plugin for all the keys now on the list 😉
View attachment 140030

I appreciate the help, but my game still insists on using X and Z. Or anything else for the matter. Maybe there's a conflict with another plug-in. I'm using MV version 1.5.2.

Glad it helped other people though.
OK, I got it to work. As I suspected, Yanfly's ButtonCommonEvents was the culprit. The plugin assigns the buttons in several different places under different conditions.

If anyone is using Yanfly's plugin, this is what you need to do:

1. Comment out the unwanted keys in rpg_core.js.

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   //    <---------------  HERE
    // 90: 'ok',       // Z   //    <---------------  HERE
    96: 'escape',   // numpad 0
    98: 'down',     // numpad 2
    100: 'left',    // numpad 4
    102: 'right',   // numpad 6
    104: 'up',      // numpad 8
    120: 'debug'    // F9
};

2. Open the Button Common Events plugin and look for more assignments of the keys. Comment out those as well:

This part of the plugin restores the keys original functions (instead of common events). I commented out X and Z in this part.

JavaScript:
Input._revertButton = function(button) {
  if (button === 'OK') {
    this.keyMapper[13] = 'ok';
    this.keyMapper[32] = 'ok';
    // this.keyMapper[90] = 'ok';
  } else if (button === 'CANCEL') {
    this.keyMapper[45] = 'escape';
    // this.keyMapper[88] = 'escape';
    this.keyMapper[96] = 'escape';
  } else if (button === 'DASH') {
    this.keyMapper[16] = 'shift';
  } else if (button === 'PAGEUP') {
    this.keyMapper[33] = 'pageup';
    this.keyMapper[81] = 'pageup';
  } else if (button === 'PAGEDOWN') {
    this.keyMapper[34] = 'pagedown';
    this.keyMapper[87] = 'pagedown';
  } else if (button === 'LEFT') {
    this.keyMapper[37] = 'left';
    this.keyMapper[100] = 'left';
  } else if (button === 'UP') {
    this.keyMapper[38] = 'up';
    this.keyMapper[104] = 'up';
  } else if (button === 'RIGHT') {
    this.keyMapper[39] = 'right';
    this.keyMapper[102] = 'right';
  } else if (button === 'DOWN') {
    this.keyMapper[40] = 'down';
    this.keyMapper[98] = 'down';
  } else if (button === 'ALL') {
    this.keyMapper[13] = 'ok';
    this.keyMapper[32] = 'ok';
    // this.keyMapper[90] = 'ok';   //    <---------------  HERE
    this.keyMapper[45] = 'escape';
    // this.keyMapper[88] = 'escape';   //    <---------------  HERE
    this.keyMapper[96] = 'escape';
    this.keyMapper[16] = 'shift';
    this.keyMapper[33] = 'pageup';
    this.keyMapper[81] = 'pageup';
    this.keyMapper[34] = 'pagedown';
    this.keyMapper[87] = 'pagedown';
    this.keyMapper[37] = 'left';
    this.keyMapper[100] = 'left';
    this.keyMapper[38] = 'up';
    this.keyMapper[104] = 'up';
    this.keyMapper[39] = 'right';
    this.keyMapper[102] = 'right';
    this.keyMapper[40] = 'down';
    this.keyMapper[98] = 'down';
  }
}

This part switches on the common events feature - meaning, when you press a key, a common event will fire. I commented out the keys here as well:

JavaScript:
Input._switchButton = function(button) {
  if (button === 'OK') {
    if (Yanfly.Param.BCEList['enter'] !== 0) this.keyMapper[13] = 'enter';
    if (Yanfly.Param.BCEList['space'] !== 0) this.keyMapper[32] = 'space';
    if (Yanfly.Param.BCEList['z'] !== 0) this.keyMapper[90] = 'z';
  } else if (button === 'CANCEL') {
    if (Yanfly.Param.BCEList['ins'] !== 0) this.keyMapper[45] = 'ins';
    if (Yanfly.Param.BCEList['x'] !== 0) this.keyMapper[88] = 'x';
    if (Yanfly.Param.BCEList['num0'] !== 0) this.keyMapper[96] = 'num0';
  } else if (button === 'DASH') {
    if (Yanfly.Param.BCEList['keyShift'] !== 0) this.keyMapper[16] = 'keyShift';
  } else if (button === 'PAGEUP') {
    if (Yanfly.Param.BCEList['pageUp'] !== 0) this.keyMapper[33] = 'pageUp';
    if (Yanfly.Param.BCEList['q'] !== 0) this.keyMapper[81] = 'q';
  } else if (button === 'PAGEDOWN') {
    if (Yanfly.Param.BCEList['pageDown'] !== 0) this.keyMapper[34] = 'pageDown';
    if (Yanfly.Param.BCEList['w'] !== 0) this.keyMapper[87] = 'w';
  } else if (button === 'LEFT') {
    if (Yanfly.Param.BCEList['dirLeft'] !== 0) this.keyMapper[37] = 'dirLeft';
    if (Yanfly.Param.BCEList['num4'] !== 0) this.keyMapper[100] = 'num4';
  } else if (button === 'UP') {
    if (Yanfly.Param.BCEList['dirUp'] !== 0) this.keyMapper[38] = 'dirUp';
    if (Yanfly.Param.BCEList['num8'] !== 0) this.keyMapper[104] = 'num8';
  } else if (button === 'RIGHT') {
    if (Yanfly.Param.BCEList['dirRight'] !== 0) this.keyMapper[39] = 'dirRight';
    if (Yanfly.Param.BCEList['num6'] !== 0) this.keyMapper[102] = 'num6';
  } else if (button === 'DOWN') {
    if (Yanfly.Param.BCEList['dirDown'] !== 0) this.keyMapper[40] = 'dirDown';
    if (Yanfly.Param.BCEList['num2'] !== 0) this.keyMapper[98] = 'num2';
  } else if (button === 'ALL') {
    if (Yanfly.Param.BCEList['enter'] !== 0) this.keyMapper[13] = 'enter';
    if (Yanfly.Param.BCEList['space'] !== 0) this.keyMapper[32] = 'space';
    // if (Yanfly.Param.BCEList['z'] !== 0) this.keyMapper[90] = 'z';   //    <---------------  HERE
    if (Yanfly.Param.BCEList['ins'] !== 0) this.keyMapper[45] = 'ins';
    // if (Yanfly.Param.BCEList['x'] !== 0) this.keyMapper[88] = 'x';   //    <---------------  HERE
    if (Yanfly.Param.BCEList['num0'] !== 0) this.keyMapper[96] = 'num0';
    if (Yanfly.Param.BCEList['keyShift'] !== 0) this.keyMapper[16] = 'keyShift';
    if (Yanfly.Param.BCEList['pageUp'] !== 0) this.keyMapper[33] = 'pageUp';
    if (Yanfly.Param.BCEList['q'] !== 0) this.keyMapper[81] = 'q';
    if (Yanfly.Param.BCEList['pageDown'] !== 0) this.keyMapper[34] = 'pageDown';
    if (Yanfly.Param.BCEList['w'] !== 0) this.keyMapper[87] = 'w';
    if (Yanfly.Param.BCEList['dirLeft'] !== 0) this.keyMapper[37] = 'dirLeft';
    if (Yanfly.Param.BCEList['num4'] !== 0) this.keyMapper[100] = 'num4';
    if (Yanfly.Param.BCEList['dirUp'] !== 0) this.keyMapper[38] = 'dirUp';
    if (Yanfly.Param.BCEList['num8'] !== 0) this.keyMapper[104] = 'num8';
    if (Yanfly.Param.BCEList['dirRight'] !== 0) this.keyMapper[39] = 'dirRight';
    if (Yanfly.Param.BCEList['num6'] !== 0) this.keyMapper[102] = 'num6';
    if (Yanfly.Param.BCEList['dirDown'] !== 0) this.keyMapper[40] = 'dirDown';
    if (Yanfly.Param.BCEList['num2'] !== 0) this.keyMapper[98] = 'num2';
  }
};

There's a pretty hefty part of the plugin called Input Key Mapper. I found that if I commend out the keys in the Revert and Switch parts of the plugin, I didn't need to alter anything else, so you can leave that part alone even though it has key bindings:

JavaScript:
//=============================================================================
// Input Key Mapper
//=============================================================================

// [No changes needed]

And, at long last, we have X and Z disabled.
Thank you, ct_bolt, for your help - you were right, but unfortunately another plugin was also altering key bindings, so there was more to be done.

P.S,
This issue came to light during a beta test of my game. I thought I disabled Z/X years ago when I first started the project. It didn't even occur to me they might still be functioning, but a beta tester used them, which broke some features. This saved me from embarrassment when I actually release the game! Conclusion of this story is: test your games, watch real people play, it is really important.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/solved-is-there-a-simple-way-to-unbind-disable-the-x-and-z-keys.120285/