dethrace-labs / dethrace

Reverse engineering the 1997 game "Carmageddon"
https://twitter.com/dethrace_labs
GNU General Public License v3.0
669 stars 38 forks source link

Holding down SHIFT makes key repeat go crazy quick #321

Closed madebr closed 1 year ago

madebr commented 1 year ago

In places where you can enter text, such as the Driver Selection menu or Save Game menu, when you hold down the SHIFT key while entering text, the text is repeated very fast.

How to reproduce

  1. Start a new game
  2. Click on one of the drivers
  3. Remove all text using backspace
  4. Hold down the SHIFT (with your pink)
  5. Press any other letter key

Expected result

The letter is entered, with a moderate speed

Actual result

The complete input box is filled with the letter

madebr commented 1 year ago

The issue happend here in TypeKey: https://github.com/dethrace-labs/dethrace/blob/99473ffdf53cc6565ed8beac6a9bcfc1805f98e8/src/DETHRACE/common/input.c#L791-L792

The PDGetASCIIFromKey checks whether the SHIFT key is down, which will modify the last key that was down.

Modifying the above lines to:

{
    printf("before: gLast_key_down=%d\n", gLast_key_down);
    int v = PDGetASCIIFromKey(pKey);
    printf("after: gLast_key_down=%d\n", gLast_key_down);
    DoRLTypeLetter(v, pSlot_index);
}

will print the following output (with #322 applied) when typing text with the SHIFT key down.

before: gLast_key_down=21
after: gLast_key_down=0

Because gLast_key_down was modified to KEY_SHIFT_ALL, the code will a new key has been entered.