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

SCUMM: Fix remapping of numpad keys on EVENT_KEYUP #5406

Merged
merged 1 commit into from Nov 13, 2023

Conversation

larsamannen
Copy link
Contributor

Dpad buttons are by default remapped to numpad keys. Up/Down are KEYCODE_KP8/KEYCODE_KP2 and Left/right are KEYCODE_KP4/KEYCODE_KP6.

The numpad keys are remapped to have a corresponding ASCII value since the state of the keys are stored in the _keyDownMap array, indexed by the ASCII value.

It was found that the ASCII values were calculated incorrectly for EVENT_KEYUP events but correctly for EVENT_KEY DOWN events. In the latter cases the keyboard event was stored to the _keyPressed member variable. The keycode was checked and if being a numpad key the corresponding ASCII value was calculated. The key state was then stored in the _keyDownMap array using the calculated ASCII value.

For the EVENT_KEYUP events the keyboard event was not stored to the _keyPressed member variable. The keycode was still checked using the _keyPressed variable. However the _keyPressed could have been reset causing the ASCII calculation to fail for the numpad key. The raw ASCII value of the keyboard event was instead being used to reset the key state in the _keyDownMap array causing the numpad key to be left in a pressed state.

This was found when plaing the Lunar Lander mini game in "The Dig" using the virtual gamepad controller in iOS.

Fix it by writing the keyboard event to the _keyPressed variable and use the corresponding ASCII value when reseting the key state in the _keyDownMap array.

Dpad buttons are by default remapped to numpad keys. Up/Down are
KEYCODE_KP8/KEYCODE_KP2 and Left/right are KEYCODE_KP4/KEYCODE_KP6.

The numpad keys are remapped to have a corresponding ASCII value
since the state of the keys are stored in the _keyDownMap array,
indexed by the ASCII value.

It was found that the ASCII values were calculated incorrectly for
EVENT_KEYUP events but correctly for EVENT_KEY DOWN events. In the
latter cases the keyboard event was stored to the _keyPressed member
variable. The keycode was checked and if being a numpad key the
corresponding ASCII value was calculated. The key state was then
stored in the _keyDownMap array using the calculated ASCII value.

For the EVENT_KEYUP events the keyboard event was not stored to the
_keyPressed member variable. The keycode was still checked using the
_keyPressed variable. However the _keyPressed could have been reset
causing the ASCII calculation to fail for the numpad key. The raw
ASCII value of the keyboard event was instead being used to reset
the key state in the _keyDownMap array causing the numpad key to be
left in a pressed state.

This was found when plaing the Lunar Lander mini game in "The Dig"
using the virtual gamepad controller in iOS.

Fix it by writing the keyboard event to the _keyPressed variable
and use the corresponding ASCII value when reseting the key state
in the _keyDownMap array.
@AndywinXp
Copy link
Contributor

Thank you! 🙂 Looks good to me, merging...

@AndywinXp AndywinXp merged commit e8ea447 into scummvm:master Nov 13, 2023
8 checks passed
AndywinXp added a commit that referenced this pull request Nov 13, 2023
In particular we set the _keyPressed object only when we find
an event.kbd for the numpad keys. Otherwise we immediately
get double events when pressing any key.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants