Skip to content

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

Open
tyvsmith wants to merge 1 commit 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 1 commit into
feschber:mainfrom
tyvsmith:fix/macos-missing-keycodes

Conversation

@tyvsmith
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)

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>
Copilot AI review requested due to automatic review settings May 22, 2026 18:59
Copy link
Copy Markdown

Copilot AI left a comment

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)) {
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