Skip to content

macos: map Print Screen / Scroll Lock / Pause to F13/F14/F15 - #445

Open
tyvsmith wants to merge 4 commits into
feschber:mainfrom
tyvsmith:fix/macos-missing-keycodes
Open

macos: map Print Screen / Scroll Lock / Pause to F13/F14/F15#445
tyvsmith wants to merge 4 commits into
feschber:mainfrom
tyvsmith:fix/macos-missing-keycodes

Conversation

@tyvsmith

@tyvsmith tyvsmith commented May 22, 2026

Copy link
Copy Markdown
Contributor

Problem

The keycode crate's Chromium-derived evdev→CGKeyCode table has no entry for three keys that appear on virtually every standard PC keyboard:

  • KEY_SYSRQ (99) — Print Screen
  • KEY_SCROLLLOCK (70) — Scroll Lock
  • KEY_PAUSE (119) — Pause / Break

When a Linux client sends any of these keys, the macOS emulation backend hits the Err(_) arm and silently drops the event with "unable to map key event".

This is reproducible with any software KVM (e.g. lan-mouse itself) where the sending machine is Linux and the receiving machine is macOS: pressing Print Screen on the Linux keyboard produces keycode: 0xffff on the macOS side with no key event emitted.

Fix

Add a fallback match on scancode::Linux before delegating to KeyMap::from_key_mapping. Maps the three keys to F13/F14/F15 (0x69/0x6B/0x71) respectively — the decades-old macOS convention for PC keys that have no Apple keyboard equivalent.

This allows tools on the macOS side (e.g. skhd) to bind these keys normally, since F13/F14/F15 are well-known CGKeyCodes.

Testing

  • Sent Print Screen, Scroll Lock, and Pause from an Arch Linux desktop to macOS via lan-mouse
  • Confirmed skhd -o reports keycode: 0x69 / 0x6B / 0x71 for each key respectively (previously 0xffff)
  • All other key events unaffected (fallback to existing KeyMap::from_key_mapping path)

Reparented on #449. This branch is temporarily stacked on top of #449 (fix(ci): bust stale Homebrew glib cache on macOS runners). The build macos-latest / test macos-latest failures here were not caused by this change — they are the stale Homebrew glib cache regression (search path '/opt/homebrew/Cellar/glib/2.88.0/lib' not foundlibrary 'gio-2.0' not found) that affects all open PRs and is fixed by #449. Stacking on #449 makes CI green here now. Once #449 merges, this PR will merge cleanly — its CI-fix commit drops out as a no-op after a rebase onto the updated main. The only functional change in this PR remains the macOS keycode mapping in input-emulation/src/macos.rs.

Copilot AI review requested due to automatic review settings May 22, 2026 18:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a macOS-specific fallback mapping so Linux evdev keys that lack entries in the keycode crate’s evdev→CGKeyCode table (Print Screen / Scroll Lock / Pause) still generate usable key events on macOS by mapping them to the conventional F13/F14/F15 CGKeyCodes.

Changes:

  • Add a scancode::Linux-based fallback for KEY_SYSRQ, KEY_SCROLLLOCK, and KEY_PAUSE.
  • Map those keys to macOS F13/F14/F15 keycodes (0x69/0x6B/0x71) to enable binding in tools like skhd.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +459 to +463
let code: CGKeyCode = match scancode::Linux::try_from(key) {
Ok(scancode::Linux::KeySysrq) => 0x69, // F13
Ok(scancode::Linux::KeyScrollLock) => 0x6B, // F14
Ok(scancode::Linux::KeyPause) => 0x71, // F15
_ => match KeyMap::from_key_mapping(KeyMapping::Evdev(key as u16)) {
@tyvsmith

Copy link
Copy Markdown
Contributor Author

This is now reparented on #449, so once that merges on main, this will merge cleanly without the seemingly duplicated file to the github workflow.

tyvsmith and others added 2 commits July 24, 2026 11:29
The keycode crate's Chromium-derived table has no macOS CGKeyCode for
these three PC-only keys, so they were silently dropped. Map them to
F13/F14/F15 respectively, which is the conventional macOS stand-in for
keys that do not exist on Apple keyboards.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Apply rustfmt to fix the failing Formatting CI check.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tyvsmith
tyvsmith force-pushed the fix/macos-missing-keycodes branch from 5bf3269 to 18d61ff Compare July 24, 2026 18:38
tyvsmith and others added 2 commits July 24, 2026 14:43
Rust 1.97 clippy denies clippy::useless_borrows_in_formatting on the
`&self.config_path` arguments in src/config.rs (code inherited from
main, not part of this PR). Fixed here so CI passes; this commit can be
dropped once main carries the same fix.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The gtk-windows-build cache was evicted, and rebuilding gtk now fails
because windows-latest runners only ship Visual Studio 2026 (v18) while
gvsbuild defaults to vs2022 (v17):

  Skipping Visual Studio at "C:\Program Files\Microsoft Visual
  Studio\18\Enterprise": Doesn't match target Visual Studio version of 17
  Error: Unable to find applicable Visual Studio

Pass --vs-ver vs2026 so gvsbuild uses the installed toolchain. This is
inherited CI breakage, not part of this PR; the commit can be dropped
once main carries the same fix.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

2 participants