Skip to content

Add Right Alt+C/V → Cmd+C/V mapping for Mac streaming - #573

Open
dangnm wants to merge 3 commits into
ClassicOldSong:moonlight-noirfrom
dangnm:add_right_alt_command_c_v_mapping
Open

Add Right Alt+C/V → Cmd+C/V mapping for Mac streaming#573
dangnm wants to merge 3 commits into
ClassicOldSong:moonlight-noirfrom
dangnm:add_right_alt_command_c_v_mapping

Conversation

@dangnm

@dangnm dangnm commented Jun 28, 2026

Copy link
Copy Markdown

Summary

When streaming to a Mac via Sunshine, the Command key is not directly accessible from Android keyboards. This PR adds a preference that fully remaps the Right Alt key to Command for Mac streaming.

  • Adds a new opt-in preference "Right Alt as Command (Mac)" under keyboard settings (disabled by default)
  • When enabled, Right Alt behaves exactly like the Command key — any Right Alt+key combo becomes Command+key (e.g. Right Alt+C = Cmd+C, Right Alt+Z = Cmd+Z, Right Alt+Tab = Cmd+Tab)
  • Left Alt is completely unaffected
  • International keyboard users (e.g. Polish AltGr combos) are not impacted as the feature is disabled by default
  • Fixes a related bug where the backAsMeta preference did not update the internal modifier state, causing subsequent keys to miss the Meta modifier

How it works

When Right Alt is pressed with the preference enabled:

  1. handleSpecialKeys() intercepts the key event and sends VK_LWIN (mapped to Command on macOS by Sunshine) instead of VK_RMENU
  2. modifierFlags is updated with MODIFIER_META instead of MODIFIER_ALT
  3. getModifierState() is patched to suppress MODIFIER_ALT from Android's key event meta state when Right Alt is the only Alt held, preventing spurious Alt+Command combos from reaching the host

Files changed

  • Game.java — Right Alt → Command remapping in handleSpecialKeys(), modifier state fix in getModifierState(), backAsMeta modifier flag fix
  • PreferenceConfiguration.java — new rightAltAsMeta preference field
  • preferences.xml — new CheckBoxPreference entry
  • strings.xml — new preference title and summary strings

@dangnm dangnm changed the title Add mapping right alt to command for Mac to copy paste Add Right Alt+C/V → Cmd+C/V mapping for Mac streaming Jun 28, 2026
@ClassicOldSong

Copy link
Copy Markdown
Owner

Thank you, but why not make right alt meta directly?

@kayti

kayti commented Jun 28, 2026

Copy link
Copy Markdown

Thank you, but why not make right alt meta directly?

Right Alt is often used with special characters in many languages, e.g., Polish R ALT+A gives ą, etc. So directly mapping it would be problematic for some.

@dangnm

dangnm commented Jul 5, 2026

Copy link
Copy Markdown
Author

Thank you, but why not make right alt meta directly?

Right Alt is often used with special characters in many languages, e.g., Polish R ALT+A gives ą, etc. So directly mapping it would be problematic for some.

This is opt-in and disabled by default. The preference Right Alt as Command (Mac) must be explicitly enabled by the user. Polish and other international keyboard users are unaffected unless they choose to enable it.

@dangnm

dangnm commented Jul 5, 2026

Copy link
Copy Markdown
Author

Thank you, but why not make right alt meta directly?

Done. Right Alt is now fully remapped to Command when the preference is enabled, not just for C/V. Any Right Alt+key combo (e.g. Right Alt+Z for Cmd+Z, Right Alt+Tab for Cmd+Tab) will work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants