Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve input handling of special keys #13

Merged
merged 1 commit into from
Nov 8, 2020

Conversation

olafkryus
Copy link
Contributor

At first I noticed that F5 key used to reset the wind at the start of the custom cup doesn't work also (and this was basically the reason version 3.13 was created — oops). So I've added a line of code to fix that.
Then I realized that other F keys should be possible to assign in key setup and that is broken too. So I've added a few more lines to fix that.
Then I noticed that it's also not possible to move the start gate up in practice using the + key not on the keypad, but the one accesed by Shift+=, even though it was possible in the DOS version. Then I've noticed that not only Shift, Num Lock etc. work in "press any key"-like situations (where they didn't in the DOS version), but also are ignored by the game altogether when it comes to detection of which key was pressed. 🤕 (While looking into the code I've also noticed that the game supports a few key combos I don't remember to be documented, and I find them cool actually. But that means they also need to be supported.)
And finally I remembered that we should be also allowing some of the punctuation marks in the player name field for example. So this issue needed a thorough solution.

I've did some investigation and research.
My understanding now is that while BIOS keycodes differentiated between charcodes and scancodes on the keyboard, SDL differentiates between keycodes and scancodes. So if we press a key normally, and with Caps Lock on/Shift held, that would at all times be the same scancode, but two different charcodes (lower- and uppercase) in DOS, and on SDL one keycode but with three different modifier statuses. And not only we need to convert keycode value from Unicode to ANSI for the game to interpret it correctly, the scancodes on SDL are different too, since they use USB and not BIOS list. That would be complicated enough, but since we don't get the actual charcode on SDL, we also don't even know what character to print when Shift is used eg. with number row, since there is no information about keyboard layout used.

So a proper fix would require in my opinion reworking the game input handling mechanics, so that in case of steering input we always depend on (USB) scancode, and in text input scenario we should probably depend on the SDL Text Input handling mechanisms.

That would probably be quite intrusive to the game's code, so for now I've prepared a solution which cuts some corners, but is contained fully within the SDLPort.WaitForKeyPress procedure and works in general. Most importantly I had to assume a keyboard layout as a base for conversion of characters with the Shift modifier key. We don't need to be afraid of game receiving uppercased input now however, since that was a feature baked into BIOS keyboard handling and the game had to deal with it already. I've chosen US QWERTY trying to cover as many users as possible, I guess it's still better than not working at all. I didn't bother with setting the correct scancode for regular letters and punctuation — apart from special keys with charcode 0, the game only processes the scancode when saving and reading the key setup, but never really depends on the value. But I left the code to set it which was already there, since that is technically a more correct way to emulate the BIOS functionality. I've also modified SDLPort.KeyPressed so that pressing the modifier keys alone doesn't trigger anything, in line with DOS version.

I've conducted some behavioral testing between the DOS version and this patch, and on the surface it seems to work the same way now. Concerning processing of national characters, the a with ring above and o with diaeresis comments were swapped, so while I was at it I also added the rest of characters supported by the game as well.

@veikkos
Copy link
Member

veikkos commented Nov 8, 2020

Hey, thanks A LOT! Keyboard handling is something I indeed didn't focus too much and shortcuts were taken. I wasn't familiar with DOS version that much either so didn't know all the things that should work...

Glad you took the time to implement these improvements. I tried them quickly and it seemed to work as expected, and anyway I trust that you know the keyboard handing now way better than I do.

Let's merge that another fix too (one quesiton added) and I'll make version 2 release.

@veikkos veikkos merged commit cd189ca into suomipelit:master Nov 8, 2020
@olafkryus olafkryus deleted the fix/special-key-handling branch November 9, 2020 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants