SCUMM: Fix remapping of numpad keys on EVENT_KEYUP #5406
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.