Ancurio / mkxp

Free Software implementation of the Ruby Game Scripting System (RGSS)
GNU General Public License v2.0
513 stars 131 forks source link

Inconsistent button codes #31

Closed b6i6o6 closed 10 years ago

b6i6o6 commented 10 years ago

I have added this simple code in the update method of Scene_Map: Array.new(30){|index| index}.each { |i| if Input.trigger?(i) print i return end

I got very strange results! A = 17 Z = 18 D = 16 S = 15 Q = 14 W = 11 X = 12 C = 13 Esc = 12 Space = 13 Shift = 11 CTRL = 22 ALT = 23 F5 = 25 F6 = 26 F7 = 27 F8 = 28 F9 = 29 Down = 2 Up = 8 Left = 4 Right = 6

Note only all letters except C has a wrong code with respect to https://github.com/Ancurio/mkxp/blob/master/src/input.h, some aren't even supposed to be supported like Space which triggers a C. I have been unable to find a key which triggered the code 21 for Shift.

I thought this was related to keyboard region so I switched my Belgian keyboard to US but that didn't affect the results.

Unless you didn't tested your button codes, which I doubt, perhaps it may be related to the Apple Keyboard or Mac OS X in general?

Ancurio commented 10 years ago

If you're in the French speaking part of Belgium, does that mean you use an AZERTY keyboard? You should use something like this as reference and compare your results again =)

Why this is happening: SDL2 uses something called "scancodes", which lets me bind actions not to key letters like usual (layout dependent), but actual key locations (layout independent), so the key a user needs to press for eg. "L" is always in the same physical location on their keyboard, independently on what is printed on the key. This is helpful because, for example, on German keyboards Z and Y have switched positions, which often makes games hard to play for Germans with keybinds on ZXC.

As for Space, are you sure it's not "C" in RMXP? I was sure it is.

As for Shift, since the physical key is by default bound to "A" it is masked by this button code, but both "A" and "Shift" should be triggered by the Shift key. Your code returns on the first match, so you never see the second button code.

Edit: Forgot to mention, this shouldn't be too much of a hindrance when mkxp finally gets a proper key rebind UI (which will show the user the letter that is actually printed on the key), but that's still a work in progress at this point.

b6i6o6 commented 10 years ago

Yes I have an AZERTY keyboard, I meant switching to QWERTY when I was talking about switching my keyboard region to US! ;-)

Ok I understand how SDL2 scancodes work and that's clever in terms of compatibility. It's a bit tricky to develop with when you don't have an QWERTY keyboard though, as you need to code your bindings with respect to their reference keyboard which doesn't match yours... ^^' That's good to know though, thank you!

However, I don't understand how the codes should match to the reference keyboard you linked me, because my A key is where their Q key is, so when I press A, SDL should think I press Q in their reference keyboard (if I understood it correctly), but there is no code for key Q in input.h.

I'm not an experienced RMXP developer, I'm just beginning actually so I didn't know about the Space key being treated like a C, thank you.

However, how is the physical shift key bound to A? You mean in RMXP or in SDL? It would be strange either way, considering Shift has its own button code, why link it to A?

Ancurio commented 10 years ago

However, I don't understand how the codes should match to the reference keyboard you linked me, because my A key is where their Q key is, so when I press A, SDL should think I press Q in their reference keyboard (if I understood it correctly), but and there is no code for key Q in input.h.

In RMXP, there is something I call "virtual buttons". For example, "C" is a virtual button that is mostly used as "Accept", or "B", which mostly means "Cancel". RMXP then let's you bind physical keys (on your keyboard) to these virtual keys, for example, "Enter" and "Space" are both bound to "C" by default so you can use these keys to accept actions in menus etc.. Joystick buttons are bound to these virtual buttons too:

All the button codes you see in input.h represent virtual keys; they're not related to actual letters on the keyboard. These are the default binds in the RMXP UI: page3

Joystick buttons are bound to these virtual buttons too: page2

However, how is the physical shift key bound to A? You mean in RMXP or in SDL? It would be strange either way, considering Shift has its own button code, why link it to A?

Shift is just a convenient button, which you could eg. use to sprint with your hero, so it is bound to the virtual button "A".

b6i6o6 commented 10 years ago

Wow that's even more complicated than I thought! So I press A on my keyboard, which is a Q for SDL, which is an L for RMXP, which is a 17 ! This is madness! :p

That makes A LOT more sense now, and the keybinds are consistent finally, thank you for taking the time to teach me! ;-)

Ancurio commented 10 years ago

To be fair, 95% of RPG Maker games don't use much more than arrow keys and Enter+Escape to play.