Input keymapper

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
424
Reaction score
171
First Language
Dutch
Primarily Uses
RMMV
if (Input.isPressed('pagedown')){ // works}if (Input.isPressed(33)){ // does not work}
Code:
var alias_silv_mm_onKeyDown = Input._onKeyDown;Input._onKeyDown = function(event){	switch(event.keyCode)	{		case 33:		  // works but also performs all these checks when we don't need to check for a keypress (because the window is not active/loaded or whatever...)	          break;	}}
I can't always use strings because the keymapping for some reason by default is incomplete:

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};so 'pagedown' may work, but 'home', or 'end', 'ins', etc. will obviously not work. What is the best way to check if a key is being held down while still having a configurable key?

Possible solutions:

1. overwrite/extend the keymapper

Problem is that when more than one plugin does this and they use a different string (even without overwriting) they will be incompatible with each other. Also you can't (should not) change the default RM bindings.

2. Copy-past & rewrite an entire new plugin manager

Aside from the fact that it is stupid to have 2 plugin managers, this will have 100% compatibility with other plugins. Sadly if others will do this too, we end up with 10-20 plugin managers in our project.

3. One person creates a univseral plugin or remapping and EVERYONE agrees to only use this one.

This would work, if all other plugin devs would abide to this. If not this won't work.

4. RPG Maker updates their keymapping to include atleast the first ~256 keys

Knowing RPG Maker, not gonna happen. Would be the best solution. Or they could support numeric values instead of only string values as well.

5. alias the update of the Input manager

Very bad for performance. Example: The inputmanager will then check every frame in the titlescreen if you didn't open your inventory... Also has many if-checks and it just a big mess overall. Have seen some people use this dirty hack...

Basically there is no epic solution to the problem..
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
That's because the Input code specifically checks for the strings, and it's true that by default it's not complete. However, you can add the numbers to the map to give them keys yourself. It's definitely a big step up from Ace and others, because now it's just a matter of adding in the numbers and the corresponding keys. It makes input plugins really easy. Like the one I already made! I haven't made a topic for it here yet, as I'd like to get a few more plugins ready before I start making topics, but feel free to use this plugin either as a reference, or to just use it. You can use it in any game, just credit me, please :) . If you just use it for reference, no need to credit me.
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
424
Reaction score
171
First Language
Dutch
Primarily Uses
RMMV
So we basically have to override the whole thing everytime I allow people to use custom keys... It's a step up from Ace but still why couldn't they just add the complete list now I must override it in every such plugin...

I see other plugin devs use varies methods to solve this problem, most just hacking their way around. Some in not such good ways but okay.

Your code does seem to have a few mistakes in it (just quickly looked at it):

35: params["Home" ], // Home <<<< should be 36 36: params["End" ], // End <<< should be 35// Also you use uppercase as well while the default uses only lowercase. I believe this does matter.Also your script seems to bug the default RM code.

I just quickly made this one:

Input.keyMapper ={    8:   'backspace'    ,    9:   'tab'          ,        13:  'ok'         , // enter    16:  'shift'        ,    17:  'control'      ,    18:  'alt'          ,    19:  'pause'        , // pause/break    20:  'capslock'     ,    27:  'escape'       ,    32:  'ok'           , // space    33:  'pageup'       ,    34:  'pagedown'     ,    35:  'end'          ,    36:  'home'         ,    37:  'left'         ,    38:  'up'           ,    39:  'right'        ,    40:  'down'         ,    45:  'insert'       ,    46:  'delete'       ,        48:  '0'            ,    49:  '1'            ,    50:  '2'            ,    51:  '3'            ,    52:  '4'            ,    53:  '5'            ,    54:  '6'            ,    55:  '7'            ,    56:  '8'            ,    57:  '9'            ,        65:  'a'            ,    66:  'b'            ,    67:  'c'            ,    68:  'd'            ,    69:  'e'            ,    70:  'f'            ,    71:  'g'            ,    72:  'h'            ,    73:  'i'            ,    74:  'j'            ,    75:  'k'            ,    76:  'l'            ,    77:  'm'            ,    78:  'n'            ,    79:  'o'            ,    80:  'p'            ,    81:  'pageup'       , // q    82:  'r'            ,    83:  's'            ,    84:  't'            ,    85:  'u'            ,    86:  'v'            ,    87:  'pagedown'     , // w    88:  'escape'       , // x    89:  'y'            ,    90:  'ok'           , // z        91:  'windows left' , // left windows key    92:  'windows right', // right windows key    93:  'media'        , // windows media key        96:  'numpad0'      ,    97:  'numpad1'      ,    98:  'numpad2'      ,    99:  'numpad3'      ,    100: 'numpad4'      ,    101: 'numpad5'      ,    102: 'numpad6'      ,    103: 'numpad7'      ,    104: 'numpad8'      ,    105: 'numpad9'      ,    106: '*'            ,    107: '+'            ,    109: '-'            , // same as keycode 189 but for different browsers...    110: 'decimal point',    111: '/'            ,        112: 'f1'           ,    113: 'f2'           ,    114: 'f3'           ,    115: 'f4'           ,    116: 'f5'           ,    117: 'f6'           ,    118: 'f7'           ,    119: 'f8'           ,    120: 'debug'        , // f9    121: 'f10'          ,    122: 'f11'          ,    123: 'f12'          ,        144: 'num lock'     ,    145: 'scroll lock'  ,    186: ','            ,    187: '='            ,    188: ','            ,    189: '-'            , // dash, same as keycode 109 but for different browsers...    190: '.'            ,    191: '/'            ,    192: 'grave accent' ,    219: '['            ,    220: 'backslash'    ,    221: ']'            ,    222: 'single quote'};
- The problem with this override is that other scripts will break. 32: params['space' ],  for example must be 'ok'. So annoying. If not the default-RM code will bug.

- Another ~250 lines of nonsense code in every plugin (unless I use a universal core script that everyone uses).

- And 109 and 189 are gonna cause problems for sure at some point.

- On top of all that most of my plugins are now incompatible with yours and probably many others. This is already one hell of a mess.

I'm doing something wrong or I need a better solution.
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
No need to override. I use this to enable WASD movement (Q and W are normally pageup/pagedown, that's why i unmap Q):

Code:
(function($) {    $[81] = undefined;    // Q    $[87] = 'up';         // W    $[65] = 'left';       // A    $[83] = 'down';       // S    $[68] = 'right';      // D})(Input.keyMapper);
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
424
Reaction score
171
First Language
Dutch
Primarily Uses
RMMV
Also with your method. If I write:

(function($) { $[8] = 'backspace' ; $[9] = 'tab' ; $[13] = 'enter' ; // replaced ok with enter, but this will bug the default-RM code (no longer responds to ok) // etc.})(Input.keyMapper);The global enter-key will obviously break. It still counts as an override.
How can I bind both enter and ok to the same keycode? Same problem with x and cancel, etc.

Full code:

Code:
(function($) {	$[8]   = 'backspace'     ;	$[9]   = 'tab'           ;		$[13]  = 'ok'            ; // enter	$[16]  = 'shift'         ;	$[17]  = 'control'       ;	$[18]  = 'alt'           ;	$[19]  = 'pause'         ; // pause/break	$[20]  = 'capslock'      ;	$[27]  = 'escape'        ;	$[32]  = 'ok'            ; // space	$[33]  = 'pageup'        ;	$[34]  = 'pagedown'      ;	$[35]  = 'end'           ;	$[36]  = 'home'          ;	$[37]  = 'left'          ;	$[38]  = 'up'            ;	$[39]  = 'right'         ;	$[40]  = 'down'          ;	$[45]  = 'insert'        ;	$[46]  = 'delete'        ;		$[48]  = '0'             ;	$[49]  = '1'             ;	$[50]  = '2'             ;	$[51]  = '3'             ;	$[52]  = '4'             ;	$[53]  = '5'             ;	$[54]  = '6'             ;	$[55]  = '7'             ;	$[56]  = '8'             ;	$[57]  = '9'             ;		$[65]  = 'a'             ;	$[66]  = 'b'             ;	$[67]  = 'c'             ;	$[68]  = 'd'             ;	$[69]  = 'e'             ;	$[70]  = 'f'             ;	$[71]  = 'g'             ;	$[72]  = 'h'             ;	$[73]  = 'i'             ;	$[74]  = 'j'             ;	$[75]  = 'k'             ;	$[76]  = 'l'             ;	$[77]  = 'm'             ;	$[78]  = 'n'             ;	$[79]  = 'o'             ;	$[80]  = 'p'             ;	$[81]  = 'pageup'        ; // q	$[82]  = 'r'             ;	$[83]  = 's'             ;	$[84]  = 't'             ;	$[85]  = 'u'             ;	$[86]  = 'v'             ;	$[87]  = 'pagedown'      ; // w	$[88]  = 'escape'        ; // x	$[89]  = 'y'             ;	$[90]  = 'ok'            ; // z		$[91]  = 'windows left'  ; // left windows key	$[92]  = 'windows right' ; // right windows key	$[93]  = 'media'         ; // windows media key		$[96]  = 'numpad0'       ;	$[97]  = 'numpad1'       ;	$[98]  = 'numpad2'       ;	$[99]  = 'numpad3'       ;	$[100] = 'numpad4'       ;	$[101] = 'numpad5'       ;	$[102] = 'numpad6'       ;	$[103] = 'numpad7'       ;	$[104] = 'numpad8'       ;	$[105] = 'numpad9'       ;	$[106] = '*'             ;	$[107] = '+'             ;	$[109] = '-'             ; // same as keycode 189 but for different browsers...	$[110] = 'decimal point' ;	$[111] = '/'             ;		$[112] = 'f1'            ;	$[113] = 'f2'            ;	$[114] = 'f3'            ;	$[115] = 'f4'            ;	$[116] = 'f5'            ;	$[117] = 'f6'            ;	$[118] = 'f7'            ;	$[119] = 'f8'            ;	$[120] = 'debug'         ; // f9	$[121] = 'f10'           ;	$[122] = 'f11'           ;	$[123] = 'f12'           ;		$[144] = 'num lock'      ;	$[145] = 'scroll lock'   ;	$[186] = ','             ;	$[187] = '='             ;	$[188] = ','             ;	$[189] = '-'             ; // dash ; same as keycode 109 but for different browsers...	$[190] = '.'             ;	$[191] = '/'             ;	$[192] = 'grave accent'  ;	$[219] = '['             ;	$[220] = 'backslash'     ;	$[221] = ']'             ;	$[222] = 'single quote'})(Input.keyMapper);
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
If you want the user to be able to specify keys as plugin parameters, i wouldn't use key names, but the keyCode and have a link to a site like http://help.adobe.com/en_US/AS2LCR/Flash_10.0/00000520.html in you @help section.


/edit: This probably won't work unless you would override Input._onKeyDown and Input._onKeyUp, too :/
 
Last edited by a moderator:

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
424
Reaction score
171
First Language
Dutch
Primarily Uses
RMMV
Indeed that's the problem. Regular keycodes don't work without more messing around in the Input class. And strings cause all sorts of problems.

So I'm looking for a proper solution that does not interfere with other plugins and especially not with the default RM code.

I know several ways to implement custom keys, but I'm looking for the best implementation and not some dirty hack or some code that causes compatibility problems or whatever.
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
I would do it like this:

- Receive the key code you want to register in your plugin.

- If it doesn't already exist in keyMapper, create a new mapping. Use a unique string, that doesn't interfere with anything already existing.

- Create a mapping between the entry in keyMapper and your own action.

- When testing for input, test for the mapping action, so it will resolve either to your own or an already existing one.

Code:
(function() {        // Key to be mapped. Can be received via plugin parameter.    var _key = 65;        var _keyString = Input.keyMapper[_key] || (Input.keyMapper[_key] = 'myUniqueKey');    })();
You would then test for _keyString.
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
You were correct about Home and End being switched. My mistake, I've fixed that. However you weren't entirely correct about them being uppercase. You're right that the final input code should be lowercase, and my plugin does not change that itself. The uppercase letters in there are getting parameter values. The plugin allows you to manually rebind each and every key in the typical ASCII table, and the number pad.

You do not need to leave the spacebar mapped to 'ok'. There's absolutely nothing stopping you from changing it, except yourself. If you rebind the spacebar to something else, that's not going to break the game, because enter and 'x' are both also bound to 'ok'. My plugin has the default keybindings as they were in RM, as well as every other key on the US English keyboard.

You don't need to remap ever key, as Iavra as explained. You only need to change what you need.

109 and 189 shouldn't be any problem. They are different keys. In fact, the way my plugin is setup, they act as the same key, so you don't have to worry about that.

There's really no reason they're incompatible. They will still work fine together, your plugin simply has to come after mine. Programming is a flow, or order, of instructions. If your plugin comes after mine and rebinds some keys, your rebinds will change mine, and your plugin shall work fine unless someone else changes it later on. If your plugin were to come before mine, then the keybinds would be rewritten by my plugin. Just because we change the same thing doesn't necessarily mean we're incompatible. It could just mean we have to be more careful about the order we have our plugins loaded in as :)
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
424
Reaction score
171
First Language
Dutch
Primarily Uses
RMMV
You do not need to leave the spacebar mapped to 'ok'. There's absolutely nothing stopping you from changing it, except yourself. If you rebind the spacebar to something else, that's not going to break the game, because enter and 'x' are both also bound to 'ok'. My plugin has the default keybindings as they were in RM, as well as every other key on the US English keyboard.
It still breaks the spacebar in the default RM code. Not to mention what would happen if I would change all 3. Not an option. Also your keybinding may be default to some standard, another scripter may decide to use different ones (like I did). And voila our scripts are no longer compatible.

- If it doesn't already exist in keyMapper, create a new mapping. Use a unique string, that doesn't interfere with anything already existing.
Won't work. Because the number must be unique, not the string. And if my string is called "spacebar" and a string already exists for that number called "spcbar" then we have a problem.

You don't need to remap ever key, as Iavra as explained. You only need to change what you need.
Because I allow users to remap the plugin key used via the plugin parameter I need ALL keys all the time. So yes I need like +250 lines of code in every small plugin now that has a key... RPG Maker is so old by now, still no decent and  complete Input manager for PC... I still have to code keybinding myself in end-2015...

109 and 189 shouldn't be any problem. They are different keys. In fact, the way my plugin is setup, they act as the same key, so you don't have to worry about that.
Ah okay I didn't test that yet.

Mine will not just rebind some, it will totally overwrite yours. And if it comes before yours and I mapped them with a ',' and you wrote a 'comma' for the string, then we have yet another big problem. Because one of the 2 scripts is gonna bug (some keys won't respond). I (quickly) tried it. Not compatible.

I think I'm just gonna overwrite the whole Input._onKeyDown() and Input._onKeyUp methods(). like

if (buttonName) { this._currentState[buttonName] = true;}else { // use numbers, no strings so they will be the same for every plugin}But hey that would also cause problems when someone else also overwrites it with different string values... So the solution is, overwrite this, and do NOT use string values but stick to keycodes (they should always be the same for everyone).

This way if another script also overwrites it, it will simply overwrite the same data and all scripts will continue to work.

After some looking around: goddamnit I must also overwrite all the Input.isPressed() and such... Man I will end up with a whole new Input class.... You know what, **** rpg maker, I just make a whole new input class that only accepts numbers. Sure I will have 2 input managers to update per update-cycle but really, I'm getting so tired of this, costing me too much time for something that should have been there by default. And  tired of hacking around as well.
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
If you intend to rewrite the entire Input module, then you should look into the one that's already been released. I don't have a link to it, but one exists.

It still breaks the spacebar in the default RM code. Not to mention what would happen if I would change all 3. Not an option. Also your keybinding may be default to some standard, another scripter may decide to use different ones (like I did). And voila our scripts are no longer compatible.
If you change the keybind, then you have to be prepared for the consequences. I'd hardly consider changing one key, when there are 2 other options for the same function, to be breaking anything. 

Because I allow users to remap the plugin key used via the plugin parameter I need ALL keys all the time. So yes I need like +250 lines of code in every small plugin now that has a key... RPG Maker is so old by now, still no decent and  complete Input manager for PC... I still have to code keybinding myself in end-2015...
If you allow Game Devs to rebind the keys in the game using plugin commands, and you intend to make multiple plugins that have key bindings, just make or adopt one input plugin for your plugins. Rewriting 250 or so lines for keybindings in each different plugin isn't just inefficient, it's just plain stupid. And if you're concerned that, by allowing Game Devs to change keybinds, they might rebind all keys off of 'ok' or 'cancel' or something and break their game's input, then that's something they have to worry about, not you. I've been in this community for just about 3 years now. For the most part of all that time, I've spent my time scripting various things. I've certainly learned a lot from back then. But one of the most important things I learned is that, no matter how hard you try, you can't fix stupid. If you try to Idiot-Proof your plugins, someone will still find a way to break it in what will seem like the dumbest way possible. So, what I intend to tell you is that it isn't your job to make it idiot-proof. It's your job to just outline some issues that can happen if the user doesn't follow the instructions correctly. Will you still get people that do the exact thing you explicitly say not to? Yes. There's a funny little thing with people where they don't read instructions, and then complain that you suck, it's broken, fix it. At that point, all you can do is point out that their issue is known to be caused by their own ignorance.

It's not your job to keep people from making stupid mistakes. If you try to do so, you'll just make the work harder on yourself.

Mine will not just rebind some, it will totally overwrite yours. And if it comes before yours and I mapped them with a ',' and you wrote a 'comma' for the string, then we have yet another big problem. Because one of the 2 scripts is gonna bug (some keys won't respond). I (quickly) tried it. Not compatible.
Then yes, this is incompatible. But if you intend to use all the keybinds and allow them to be remapped, then why not use my, or someone else's input plugin? You could simple create a small helper-plugin that just rebinds keys in the keyMapper object va plugin commands. That'd be easier for you.

I think I'm just gonna overwrite the whole Input._onKeyDown() and Input._onKeyUp methods(). like

if (buttonName) { this._currentState[buttonName] = true;}else { // use numbers, no strings so they will be the same for every plugin}But hey that would also cause problems when someone else also overwrites it with different string values... So the solution is, overwrite this, and do NOT use string values but stick to keycodes (they should always be the same for everyone).

This way if another script also overwrites it, it will simply overwrite the same data and all scripts will continue to work.

After some looking around: goddamnit I must also overwrite all the Input.isPressed() and such... Man I will end up with a whole new Input class.... You know what, **** rpg maker, I just make a whole new input class that only accepts numbers. Sure I will have 2 input managers to update per update-cycle but really, I'm getting so tired of this, costing me too much time for something that should have been there by default. And  tired of hacking around as well.
Don't do that. You can hate the input module all you want, and you could want to create your own Input class with only numbers as much as you want. But it won't fix your problem. In fact, you're going to be doing more work to create a less-compatible plugin. I fail to see what's "costing you too much time". You want to rebind key, so do it. Nothing is stopping you from changing what key are bound to what internal input strings. You clearly don't care about compatibility if you're willing to make an entirely separate Input class.

And sorry to rain on your parade, but you will not get the same inputs using the numbers. The fact is that with different keyboard layouts, the numbers will still go with what letter they correspond to. This means that no matter what you try, you're never going to get the same input format for everyone in the world.

Even with the changing keyboard formats aside, you're going to use the key codes manually? Really? That's just not user-friendly design. Sure, I can look up what a code is, but why would I want to do that? I don't care what key code 87 is, not when I can just refer to it as 'w'. 

I'd like to know why you can't achieve your goal another way? You're just trying to get rebindable keys, right? If that's all you want, then I'll just add it to my own plugin for you. I intended to do so eventually. If that's not good enough for you, well then what is? If you take a little bit of time to explain to me exactly what you want to achieve, I can try to help you with it.
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
424
Reaction score
171
First Language
Dutch
Primarily Uses
RMMV
Then yes, this is incompatible. But if you intend to use all the keybinds and allow them to be remapped, then why not use my, or someone else's input plugin? You could simple create a small helper-plugin that just rebinds keys in the keyMapper object va plugin commands. That'd be easier for you.
Several reasons (like it no longer being available at some point perhaps or change of license), but the main reason is that I can't include it in my script. At least, unless you allow me to do so. I hate being dependable on other scripts esepcially for something that should have been so simple.

Another important reason btw would be that your script should not remap the default rpg maker bindings like ok and cancel. Already causing problems even w/o my script.

But I'm desperate and very angry right now (at rpg maker) so I'm be prepared to accept your plugin as a requirement for my scripts. But then they must (by default) not change the default RM mappings. If a dumb user changes it, not our problem indeed. And every other plugin that manually (not use your plugin) remaps keys has a chance of incompatibility. But we owe that to the devs of RPG Maker... Can't do anything about that without rewriting an entire new Input module or cleverly hacking into the original one but if many scripts do that, performance will go down.

Nothing is stopping you from changing what key are bound to what internal input strings. You clearly don't care about compatibility if you're willing to make an entirely separate Input class.
Oh no it wouldl be 100% compatible even with the scripters that mess up the whole Input class. Just copy-paste the whole thing, rename it to Input2, then change whatever I want. Keep the old Input class intact.  But yeah it's not efficient and looks stupid but it will do a far better job than most of the other solutions so far.

And sorry to rain on your parade, but you will not get the same inputs using the numbers. The fact is that with different keyboard layouts, the numbers will still go with what letter they correspond to. This means that no matter what you try, you're never going to get the same input format for everyone in the world.
They may have different characters for the same keycode, they keycode should be the same worldwide from what I could see. Some browsers however may bug.

I'd like to know why you can't achieve your goal another way? You're just trying to get rebindable keys, right? If that's all you want, then I'll just add it to my own plugin for you. I intended to do so eventually. If that's not good enough for you, well then what is? If you take a little bit of time to explain to me exactly what you want to achieve, I can try to help you with it.
Yes I JUST want rebindable keys that have no compatibility issues with other scripters that overwrite the keymapping or plainly hack into the Input manager. I just want to say

if (Input.IsPressed('capslock'){do something awesome} // without compatibility issues, without hacking, without rewriting a new input module, w/o aliasing the whole input update, etc. Just nothing of that garbage that I see other scripters do if possible. without coding and without compatibility problems and without license issues and dependencies and god knows what. I just want rebindable keys. Your plugin will still get compatibility issues (unless all plugins start using yours) but I can live with it. Too angry at rpg maker right now.

When will your plugin be usable? What will the license be? Can I add a copy of it next to my own script?
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
Because I allow users to remap the plugin key used via the plugin parameter I need ALL keys all the time.
No, you only need one, the one you are using. The snippet i posted above works perfectly fine for this. If there is already a string registered for this key, it just uses this, otherwise it registers a new one.
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
424
Reaction score
171
First Language
Dutch
Primarily Uses
RMMV
No, you only need one, the one you are using. The snippet i posted above works perfectly fine for this. If there is already a string registered for this key, it just uses this, otherwise it registers a new one.
No it does not. I need all. Because opening the inventory can be done through the i, but also through the caplock, the pausebutton, etc. All buttons are possible the moment you allow a script to have a configurable parameter for the action. Which dramatically increases chances for conflicts.

But nonetheless your solution won't work (well) because:

I check if key exists, key checked: 36. 36 exists (another plugin added it):

35 = 'Home Sweet Home';My plugin uses the string 'home':

Input.isPressed('home') // will always return false. Because it should now be 'Home Sweet Home' because another plugin was first and gave it a different name.We didn't add the key because it was already there. But the other plugin which added it first, did give it a different name, so our plugin now bugs. If we would chose the option to overwrite it anyway, then the other plugin will bug instead.

Now that is a problem. I already mentioned this earlier but your solution will bug eventually. In fact both of your 'plugins' would already bug when used together with mine. But I can update mine to work with Zalerinian's one and hope no other major plugin (like Yanfly's) will ever conflict with it.

I updated my OP. option 3 and 4 are the only good ones imo.
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
No, you don't check "home", you check _keyString, which might be "home", but could also be whatever value the key has been set to before your plugin.
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
424
Reaction score
171
First Language
Dutch
Primarily Uses
RMMV
Thanks you are right. I should translate string -> number -> string.->number So basically make 3 conversions instead of 1. It's only done once upon gamestart so it's not a problem performance-wise.

testcase:

Input.keyMapper[36] = 'home sweet home'; // comment this line out and it will still workvar mykeymapping = { 36:'home' };var myKey = 'home'; // 'home' comes from parametervar myRealKey = null;(function(){ var test_test = Scene_Base.prototype.create; Scene_Base.prototype.create = function() { test_test.call(this); myRealKey = mykeymapping[myKey]; if (typeof Input.keyMapper[36] != undefined) { myRealKey = Input.keyMapper[36]; } }; var test2 = Input.update; Input.update = function() { test2.call(this); if (Input.isPressed(myRealKey)){ console.log('PRESSED!, key used: ' + myKey + ' keycode used: ' + myRealKey); } } })();Indeed works.

It's still gonna be a lot of lines of code for all possible buttons. I fear I gotta make my own keymapper still that I will use in all my plugins.
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
This is...way more complex, than it has to be.

Your example can be reworked like this:

Code:
(function() {	var mykeymapping = {		home: Input.keyMapper[36] || (Input.keyMapper[36] = 'someRandomNameThatIsUnique')	};	var test2 = Input.update;	Input.update = function() {		test2.call(this);		if (Input.isPressed(mykeymapping.home)){			console.log('bla');		}	}	})();
It doesn't actually matter, what you set the mapping to, just make sure that it's unique and unlikely to overlap with keys defined by other plugins.
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
They may have different characters for the same keycode, they keycode should be the same worldwide from what I could see. Some browsers however may bug.
I was just playing around with this, and according to http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes, if I were to set my language to Netherland Dutch, for example, Q, A, and Z all have different key codes because that's how the keyboard layout is. Even using numbers, you can't guarantee that the keybindings will be the same for everyone automatically. But, this is something we have to deal with, and it's a good reason to want to add rebinds.

When will your plugin be usable? What will the license be? Can I add a copy of it next to my own script?
Technically the plugin is usable right now, it just doesn't support rebinding yet, but that should be an easy fix. As for license, All my scripts will be licensed under the CC BY 4.0 license. With that in mind, yes, you can use the plugin as it is in a copy of your next plugin, or you can make changes to it. You can even use the plugin commercially. The only restriction on the license is that I must be credited for creating the original version of that plugin.
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
424
Reaction score
171
First Language
Dutch
Primarily Uses
RMMV
Nice license!

I just finished it... Oh well I got a working version now that does:

- NOT have any sort of compatibility problem unless the other plugin is '******ed'.

- It has no extra performance drain whatsoever (should perform conversion only when a plugin is loaded)

- Looks maintainable

- Can even use different string-values for RM-keys without any problem whatsoever

- Can use multiple strings for the same key. For example: "num lock", "numlock" can both be added and will both work. or ',' and 'comma' etc. will all work at the same time.

- Does not care if the key is unique or not (if it already exists in the default Input or in another plugin, this plugin simply does not care about it).

- And on top of that I can make my existing scripts compatible now with extremely minimal changes (I only gotta add a single function call for my parameters).

The trick was using an inverted lookup table.

//=============================================================================// SilvKeys.js// Version: 1.00// License: Credit me: http://creativecommons.org/licenses/by/4.0/// Special thanks to Zalerinian & Iavra//=============================================================================/*: * @plugindesc v1.00 Silv KeyMapper <SilvKeys> * @author Silver * * @help * Example usage: * var myKey = Silv.Keys.fromStringParam('pageup'); * Silv.Minimap.ScrollKey = Silv.Keys.fromStringParam(Silv.Parameters['home']); * Note: string-value is NOT case-sensitive*/var Silv = Silv || {};Silv.Plugins = Silv.Plugins || {};Silv.Plugins.Keys = 1.00;Silv.Keys = Silv.Keys || {}; Silv.Keys.MappingInv ={    'backspace':8,    'tab':9,    'enter':13,    'shift':16,    'control':17,    'alt':18,    'pause':19,    'capslock':20,    'escape':27,    'space':32,    'pageup':33,    'pagedown':34,    'end':35,    'home':36,    'left':37,    'up':38,    'right':39,    'down':40,    'insert':45,    'delete':46,        '0':48,    '1':49,    '2':50,    '3':51,    '4':52,    '5':53,    '6':54,    '7':55,    '8':56,    '9':57,        'a':65,    'b':66,    'c':67,    'd':68,    'e':69,    'f':70,    'g':71,    'h':72,    'i':73,    'j':74,    'k':75,    'l':76,    'm':77,    'n':78,    'o':79,    'p':80,    'q':81,    'r':82,    's':83,    't':84,    'u':85,    'v':86,    'w':87,    'x':88,    'y':89,    'z':90,        'windows_left':91,    'windows_right':92,    'media':93,        'numpad0':96,    'numpad1':97,    'numpad2':98,    'numpad3':99,    'numpad4':100,    'numpad5':101,    'numpad6':102,    'numpad7':103,    'numpad8':104,    'numpad9':105,        '*':106,    '+':107,    '-':109, // same as 189    '.':110,    '/':111,        'f1':112,    'f2':113,    'f3':114,    'f4':115,    'f5':116,    'f6':117,    'f7':118,    'f8':119,    'f19':120,    'f10':121,    'f11':122,    'f12':123,        'numlock':144,    'num_lock':144,    'scrolllock':145,    'scroll_lock':145,    ';':186,    'semicolon':186,    'semi_colon':186,    '=':187,    'equal':187,    'equal_sign':187,    ',':188,    'comma':188,    //'-':189, // duplicate of 109    '.':190,    'dot':190,    'decimal':190,    'decimal_point':190,    'decimal_dot':190,    '/':191,    'forwardslash':191,    'forward_slash':191,    'grave_accent':192,    'graveaccent':192,    '[':219,    'openbracket':219,    'open_bracket':219,    'backslash':220,    ']':221,    'closebracket':221,    'close_bracket':221,    'single_quote':222};//Input.keyMapper[36] = 'home sweet home'; // DEBUG//Input.keyMapper[121] = 'f10'; // DEBUG//Input.keyMapper[187] = 'gregnergnreiogneiogneoi'; // DEBUG, yes even this works!Silv.Keys.fromStringParam = function(str){    str = str.toLowerCase();    var keyCode = Silv.Keys.MappingInv[str];    if (keyCode === undefined) { throw 'No key found for: ' + str; }    if (Input.keyMapper[keyCode] === undefined) { Input.keyMapper[keyCode] = str; }    return Input.keyMapper[keyCode];}/*// Example usage (press home-key and watch console window):// example debug keyvar myKey = Silv.Keys.fromStringParam('home');(function(){        var test2 = Input.update;    Input.update = function()    {        test2.call(this);        if (Input.isPressed(myKey)){ console.log('PRESSED!, key used: ' + myKey); }    }})();*/
I will probably upload the cleaned-up version (already converted to a plugin) along with my minimap v1.00 script in the next 2 days. I planned on finishing my minimap today :( . But the whole keybinding wasted all my time. Added a special thanks section for you guys. Now it's time to shoot some zombies :D

Ah wait there is one scenario where this plugin will still have compatibility problems. Namely when another plugin is placed after my plugin, AND rudely overwrites an existing value in the keyMapper w/o performing any checks whatsoever. But that is then fixed by changing the order of the plugins. Not to mention that it is the other plugins fault. Not my problem and I don't think that the bigger scripters will do this.

And I still think that RPG Maker should just implement this themselves... Nonsense to make us do it. They probably didn't because, Japan and their love for controller support, hate PC, etc.etc....
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,085
Members
137,583
Latest member
write2dgray
Top