Skip to content

DM_KEY_MAP gives keys of the Mac keyboard another control than the layout's: Space the R shoulder, a modifier key a button, an arrow a stick (issue #1216) - #2006

Closed
Atomsk-debug wants to merge 1 commit into
seedds:mainfrom
Atomsk-debug:mac-key-map

Conversation

@Atomsk-debug

Copy link
Copy Markdown
Contributor

What and why

For #1216. The Mac keyboard's layout was fixed in front_mac.m (key_bit, on_key); on a MacBook's keyboard Space drifts better than E in Mario Kart World, and no setting changed a key.

dm/host/key_map.h holds the names of the keys (macOS's virtual key codes: letters and digits as they are, then space, return, tab, escape, the punctuation, f1 to f12, the arrows and the modifiers lshift, rshift, lctrl, rctrl, lalt, ralt, lcmd, rcmd, capslock, fn) and of the controls (a, b, x, y, l, r, zl, zr, ls, rs, plus, minus, the D-pad, both sticks' directions, shake, none), and the parser of DM_KEY_MAP="<key>:<control>,…": a key the map names takes that control and loses the layout's, every other key keeps it, and a wrong map is refused whole with the entry in a [RED] line. front_mac.m asks the map first (key_action), then the layout; the issue's own map is DM_KEY_MAP=space:r,lshift:l,left:rleft,up:rup,right:rright,down:rdown,minus:minus,equal:plus.

The two traps the issue names: a modifier key reaches the window as a flagsChanged event with no key down or up, so the window's monitor takes those events too and reads the key's own bit of the flags (left and right apart); and a key pressed with Command held stays a menu shortcut unless a Command key is itself mapped, when such keys are the game's (said in the docs).

Docs: a Keyboard section under the Mac settings window in docs/settings.md (the layout, which no page named, and the map), and the row in docs/env_switches.tsv.

Checked

  • Tests: t_key_map (new): the names, the issue's map in any letter case and with either separator, a key given twice, the empty map, four wrong maps. make -C dm/host GAME=010015100B514000 dmhost builds; test_env_switches and test_docs pass.
  • Games run: none yet. The map's keys reach on_key by the same path as the layout's; the modifier path (flagsChanged) is new and has not been pressed in a game. I will add a run with the issue's map when I can; anyone with a keyboard and a game can try DM_KEY_MAP=space:r in the game's env.txt.
  • Devices and OS: MacBook M4, macOS 27.0, Xcode 27.2. lint_c not run locally (no LLVM clang-tidy here).

Docs

  • No game files, keys or data extracted from a game in the change or the attachments

🤖 Generated with Claude Code

@github-actions github-actions Bot added host The Horizon host: SVCs, services, threads, memory (dm/host) mac The Mac front end and app (dm/mac, front_mac.m) docs Documentation labels Nov 9, 2026
…yout's: Space the R shoulder, a modifier key a button, an arrow a stick, through a map read once at start (issue seedds#1216)

The Mac keyboard's layout was fixed in front_mac.m (key_bit, on_key): J K U I the buttons, Q E Z C
the shoulders and triggers, WASD and the arrows the sticks and the D-pad, Space the shake. On a
MacBook's keyboard Space drifts better than E in Mario Kart World, and no setting changed a key.

key_map.h holds the names of the keys (macOS's virtual key codes, letters and digits as they are,
then space, return, tab, escape, the punctuation, f1 to f12, the arrows and the modifiers) and of
the controls (the buttons, the D-pad, both sticks' directions, shake, none), and the parser of
DM_KEY_MAP="<key>:<control>,...": a key the map names takes that control and loses the layout's,
every other key keeps it, and a wrong map is refused whole with the entry in a [RED] line, so a
typo never leaves half a layout. front_mac.m asks the map first (key_action), then the layout. The
two traps of the issue: a modifier key comes as a flagsChanged event with no key down or up, so
the window's monitor takes those events too and reads the key's own bit of the flags (left and
right apart); and a key pressed with Command held stays a menu shortcut unless a Command key is
itself mapped, when such keys are the game's. docs/settings.md names the layout and the map;
docs/env_switches.tsv has the row.

Checked: t_key_map (names, the issue's map in any letter case and with either separator, a key
given twice, the empty map, four wrong maps); the Mac host builds for Super Mario Bros. Wonder;
test_env_switches and test_docs pass. Not pressed in a game yet: the map's keys reach on_key by
the same path as the layout's, and the modifier path is new.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@seedds

seedds commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Thanks for documenting the MacBook controls that made drifting easier and for testing modifier keys. I checked the PR against the three current controls proposals in #2781, #2741 and #3141. A separate DM_KEY_MAP format would give us another interface to maintain for the same player setting, so I’m closing this draft.

#1216 stays open for remapping. The Space-to-R example and the need to handle modifier-only flagsChanged events are worth carrying into that work.

@seedds seedds closed this Nov 26, 2026
chgpalmer added a commit to chgpalmer/nxnative that referenced this pull request Nov 29, 2026
The Mac front end's half of the controller mapping (host/input: keymap.h, the remap in
hle_hid.c):

- In the game (front_mac.m, keyboard_mac.h): the keyboard goes through the map in
  place of the fixed key table, Shift, Control and Option keys included (flagsChanged).
  Each player's controller table goes to the host (dm_pad_map_set) at the start and
  after every change.
- The mouse (mouselook_mac.h): with a mouse direction bound, a click on the game
  captures the pointer and its movement goes through keymap_mouse.h at 120 Hz, to
  player 1's sticks and buttons, or to the motion sensor as a controller turned in the
  hands (dm_motion_set_switch: upright in handheld mode, flat docked). Esc, a focus
  loss or the panel lets it go.
- The settings window (Launcher.swift): Controls › Controller mapping › Customize…:
  a tab per player 1-8; player 1 has its keyboard and mouse or its controller;
  click a row and press a key or chord, click a mouse button, or press a controller's
  button or push its stick; right-click for Clear, Add Input… or a mouse direction;
  Mouse and trackpad puts the mouse on a stick or the motion controls with its
  sensitivity and Invert Y axis; a Preset menu per device (keymap_presets.h). Kept as
  the saved choice launcher.DM_KEYMAP, which launcher.c checks with the host's parser.
- In the game, Window › Controller Mapping… (⌘⇧K, keymap_panel_mac.h) is the same map
  while playing: a change applies at once and is saved for the next start.
- pad_apple.h's dm_pad_state is now the one reading of a GameController pad as the
  Switch's, used by the host's pad_read and the settings window's press-to-bind
  (pad_bridge.m).

Covers seedds#2346 (mouse as a stick), seedds#2392's and seedds#356's asks (mouse look, the camera on
plain arrows), the keyboard part of seedds#386 and seedds#2006's modifier keys; keys are tracked
as pressed, so Shift let go before an arrow does not leave the right stick held (seedds#1535).

Tests: test_launcher_storage (the window with the sheet's model), test_nsp_mac_app,
test_docs, test_env_switches.

Front-ends: new: launcher.DM_KEYMAP is a saved choice, checked by the host's parser (docs/frontends.md, Saved choices)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation host The Horizon host: SVCs, services, threads, memory (dm/host) mac The Mac front end and app (dm/mac, front_mac.m)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants