NagyD / SDLPoP

An open-source port of Prince of Persia, based on the disassembly of the DOS version.
GNU General Public License v3.0
1.1k stars 140 forks source link

Use keyboard layout-aware keycodes for time cheat #275

Closed bonki closed 2 years ago

bonki commented 2 years ago

This ensures that the current keyboard layout determines the location of the '-'/'+' keys, as would be expected, and helps especially when using tenkeyless keyboards lacking a numpad. This mimics the behaviour of the original game when run under DOSBox.

NagyD commented 2 years ago

Hi,

This is a good idea!

Unfortunately, this fix does not fully work with the keyboard layout I use. '-' works okay, but '+' is not detected.

If I type '+', which is on Shift+3, then event.key.keysym.sym will be 51 = SDLK_3, instead of SDLK_PLUS. Apparently, event.key.keysym.sym tells what character would the key type without any modifiers.

I fixed it here: b92547755dcdfff4b4ca20e4a13ad9dc2b0c9b5d

Thank you again!

bonki commented 2 years ago

That's weird, I tested it with different layouts including ones where the keys require a modifier and it worked for me.

NagyD commented 2 years ago

That's weird, I tested it with different layouts including ones where the keys require a modifier and it worked for me.

Maybe it depends on the OS or the SDL version? I am using Windows 10 and SDL 2.0.14.

UPDATE: I installed SDL 2.0.22, and nothing changed.


Apparently, event.key.keysym.sym tells what character would the key type without any modifiers.

Even that is false in some cases. The French keyboard layout puts '-' where most keyboards have '6'. But when I press that key, event.key.keysym.sym will be 54 = '6', not '-'.