sm64coopdx icon indicating copy to clipboard operation
sm64coopdx copied to clipboard

Keyboard Shortcuts (input box) should be ignored with AltGr

Open Flower35 opened this issue 3 months ago • 0 comments

Bug description

While entering text into the chat box, writing characters which require the [AltGr] modifier key has the side-effects of triggering [LCtrl] combinations in djui_inputbox_on_key_down(). It might trigger unintentional text copying or text selection.


Examples

Typing combination [AltGr][A] triggers:

1 | keyboard_on_key_down      | ScanCode (1 of  3) = 0x001D  (29) = LEFT_CONTROL
2 | djui_inputbox_on_key_down | registering that CONTROL key is held down (OK so far)

https://github.com/coop-deluxe/sm64coopdx/blob/30ccad30a8be27e3f0fa34fd2ab27303a65eb4f4/src/pc/djui/djui_inputbox.c#L191

3 | keyboard_on_key_down      | ScanCode (2 of 3) = 0x0138 (312) = 256 + LEFT_ALT
4 | keyboard_on_key_down      | ScanCode (3 of 3) = 0x001E  (30) = "A"
5 | djui_inputbox_on_key_down | special case which simulates "CTRL + A" (unintentional!)

https://github.com/coop-deluxe/sm64coopdx/blob/30ccad30a8be27e3f0fa34fd2ab27303a65eb4f4/src/pc/djui/djui_inputbox.c#L284-L289

6 | keyboard_on_text_input         | text = "\xC4\x85" = (U+0105) Latin Small Letter A with Ogonek
7 | djui_inputbox_on_text_input    | NOTE: simulated "CTRL + A" selected the entire input field
8 | djui_inputbox_delete_selection | entire chat text gets discarded and replaced by a single letter, "ą"

Same issue will happen by entering [LCtrl][LAlt][A] (alternative combination honored in Windows with Polish Programmers keyboard layout).


Proposed solution

(dedicated to solve the issue on PC targets; Windows and Linux) (might require further testing; macOS uses different keyboard layouts) (SDL and DirectX might yield different ScanCodes for AltGr combinations)

  1. Add definitions in "src/pc/controller/controller_keyboard.h"
#define SCANCODE_ALT_LEFT   56
#define SCANCODE_ALT_GR    312
  1. Add a static variable which keeps track of the [Alt] and [AltGr] keys states (let's call it sHeldAltGr, similar to sHeldControl)

  2. In "src/pc/djui/djui_inputbox.c", add checks for the [Alt]/[AltGr] key (being held down, being released)

  3. Update keyboard combinations detection so that it ignores the [Alt]/[AltGr] key

if ((!sHeldAltGr && sHeldControl && scancode == SCANCODE_V) || (sHeldShift && scancode == SCANCODE_INSERT))

if (!sHeldAltGr && sHeldControl && (scancode == SCANCODE_C || scancode == SCANCODE_X))

if (!sHeldAltGr && sHeldControl && scancode == SCANCODE_A)

Desktop specs

  • OS: Windows 10, 64-bit
  • Game version: latest (0.2.3)

Flower35 avatar Apr 06 '24 05:04 Flower35