Skip to content

Commit d0faf03

Browse files
authored
Fix: Alt Gr not recognized (#399)
* Fix: Alt-Gr not recognized * Proper fix for Alt-Gr not being recognized * Add comment on codes and modifiers * Add comment on paste box * Remove comment * Improve description * Wording... * Formatting... * Improve description again
1 parent 77b4c1c commit d0faf03

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

ui/src/components/WebRTCVideo.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,31 @@ export default function WebRTCVideo() {
330330
)
331331
// Alt: Keep if Alt is pressed or if the key isn't an Alt key
332332
// Example: If altKey is true, keep all modifiers
333-
// If altKey is false, filter out 0x04 (AltLeft) and 0x40 (AltRight)
333+
// If altKey is false, filter out 0x04 (AltLeft)
334+
//
335+
// But intentionally do not filter out 0x40 (AltRight) to accomodate
336+
// Alt Gr (Alt Graph) as a modifier. Oddly, Alt Gr does not declare
337+
// itself to be an altKey. For example, the KeyboardEvent for
338+
// Alt Gr + 2 has the following structure:
339+
// - altKey: false
340+
// - code: "Digit2"
341+
// - type: [ "keydown" | "keyup" ]
342+
//
343+
// For context, filteredModifiers aims to keep track which modifiers
344+
// are being pressed on the physical keyboard at any point in time.
345+
// There is logic in the keyUpHandler and keyDownHandler to add and
346+
// remove 0x40 (AltRight) from the list of new modifiers.
347+
//
348+
// But relying on the two handlers alone to track the state of the
349+
// modifier bears the risk that the key up event for Alt Gr could
350+
// get lost while the browser window is temporarily out of focus,
351+
// which means the Alt Gr key state would then be "stuck". At this
352+
// point, we would need to rely on the user to press Alt Gr again
353+
// to properly release the state of that modifier.
334354
.filter(
335355
modifier =>
336356
altKey ||
337-
(modifier !== modifiers["AltLeft"] && modifier !== modifiers["AltRight"]),
357+
(modifier !== modifiers["AltLeft"]),
338358
)
339359
// Meta: Keep if Meta is pressed or if the key isn't a Meta key
340360
// Example: If metaKey is true, keep all modifiers

ui/src/keyboardMappings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
// Key codes and modifiers correspond to definitions in the
2+
// [Linux USB HID gadget driver](https://www.kernel.org/doc/Documentation/usb/gadget_hid.txt)
13
export const keys = {
2-
AltLeft: 0xe2,
3-
AltRight: 0xe6,
44
ArrowDown: 0x51,
55
ArrowLeft: 0x50,
66
ArrowRight: 0x4f,

0 commit comments

Comments
 (0)