Skip to content

Commit 44676f6

Browse files
committed
fix(frontend): map macOS Command and Windows Meta keys (#276)
Adds MetaLeft/MetaRight (and legacy OSLeft/OSRight) entries to the KeyboardEvent.code → keyCode table, mapped to 91/92 to match UE's LeftWindowKey/RightWindowKey scheme. KeyboardController normalizes the right-Cmd code so it no longer collides with ContextMenu (93) on Chrome/Safari, and so Firefox-on-Mac (which reports keyCode 224 for both Cmds) works too. UE-side handling for these codes is tracked separately in UE-228795.
1 parent 4cd72bc commit 44676f6

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

.changeset/macos-cmd-keys.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@epicgames-ps/lib-pixelstreamingfrontend-ue5.7": patch
3+
---
4+
5+
Map the macOS Command (and Windows Meta) keys to UE keycodes 91 (`LeftWindowKey`) and 92 (`RightWindowKey`). `KeyCodes.ts` now contains `MetaLeft`/`MetaRight` (and the legacy `OSLeft`/`OSRight`) entries, and `KeyboardController.getKeycode` normalizes the right-Cmd code so it no longer collides with `ContextMenu` (93) on browsers that report `keyCode === 93` for it, and so Firefox-on-Mac (which reports `keyCode === 224` for both Cmds) is also handled. Frontend portion of issue #276 — UE-side support for these key codes is tracked separately.

Frontend/library/src/Inputs/KeyCodes.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,17 @@ export const CodeToKeyCode: ICodeToKeyCode = Object.freeze({
110110
PageDown: 34,
111111
Insert: 45,
112112
Delete: 46,
113-
ContextMenu: 93
113+
ContextMenu: 93,
114+
// macOS Command and Windows Meta keys. The UE side maps key codes 91/92
115+
// to LeftWindowKey/RightWindowKey (currently routed to EKeys::Invalid in
116+
// stock UE — Epic-internal ticket UE-228795 enables them). Sending the
117+
// codes from the frontend is harmless when UE has no binding and lets
118+
// applications that patch UE handle Cmd/Win shortcuts.
119+
MetaLeft: 91,
120+
MetaRight: 92,
121+
// Legacy KeyboardEvent.code values some browsers historically emitted
122+
// for the same physical keys. Keep them mapped so we don't drop input
123+
// on older browsers.
124+
OSLeft: 91,
125+
OSRight: 92
114126
});

Frontend/library/src/Inputs/KeyboardController.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ export class KeyboardController implements IInputController {
130130
return SpecialKeyCodes.rightControl;
131131
} else if (keyboardEvent.keyCode === SpecialKeyCodes.alt && keyboardEvent.code === 'AltRight') {
132132
return SpecialKeyCodes.rightAlt;
133+
} else if (keyboardEvent.code === 'MetaLeft' || keyboardEvent.code === 'OSLeft') {
134+
// Browsers disagree on the legacy keyCode for the left Cmd/Win
135+
// key (Chrome/Safari report 91, Firefox on Mac reports 224).
136+
// Normalize using `code`. UE LeftWindowKey is 91.
137+
return CodeToKeyCode['MetaLeft'];
138+
} else if (keyboardEvent.code === 'MetaRight' || keyboardEvent.code === 'OSRight') {
139+
// Right Cmd/Win has the same browser disagreement, and on
140+
// Chrome/Safari it shares keyCode 93 with the ContextMenu key.
141+
// Normalize to 92 (UE RightWindowKey).
142+
return CodeToKeyCode['MetaRight'];
133143
} else {
134144
return keyboardEvent.keyCode;
135145
}

0 commit comments

Comments
 (0)