Skip to content

fix(macos): skip HotkeyListener on darwin (keyboard lib has no macOS support)#3

Open
l984-451 wants to merge 1 commit into
ayushh0110:mainfrom
l984-451:fix/macos-keyboard-guard
Open

fix(macos): skip HotkeyListener on darwin (keyboard lib has no macOS support)#3
l984-451 wants to merge 1 commit into
ayushh0110:mainfrom
l984-451:fix/macos-keyboard-guard

Conversation

@l984-451
Copy link
Copy Markdown
Contributor

Problem

On macOS, starting ScreenMind logs:

[Hotkey] Failed to register hotkey: ("Key 'b' is not mapped to any known key.", ValueError('Unrecognized character: b'))
[Hotkey] Try running as administrator for global hotkey support.

The error message blames missing admin permissions, but the real cause is that the keyboard library does not support modifier+letter hotkeys on macOS at all — keyboard.add_hotkey('ctrl+shift+b', ...) can't parse the keymap. Running with sudo does not fix it. The keyboard README itself notes "MacOS support is limited".

A separate side effect: even though add_hotkey fails, the attempt installs a low-level event tap that triggers an Input Monitoring permission prompt on every launch. Annoying and not actionable.

Fix

Skip HotkeyListener.start() (and .stop()) on sys.platform == "darwin" and print a one-liner explaining why. Existing behavior on Windows and Linux is unchanged.

import sys as _sys
if _sys.platform == "darwin":
    print("[Hotkey] Disabled on macOS (keyboard library lacks support). Use the dashboard.")
else:
    hotkey_listener.start()

This is a minimal stopgap. The proper fix is to swap keyboard for pynput (which has real macOS support) — happy to follow up with that PR if there's interest.

The `keyboard` library does not support modifier+letter global hotkeys
on macOS — `keyboard.add_hotkey('ctrl+shift+b', ...)` raises
ValueError('Unrecognized character: b'). The error message blames
"administrator" permissions, but no amount of sudo makes the lib work.

Skip the listener entirely on macOS so the error and the bogus Input
Monitoring permission prompt go away. A future commit can wire up
`pynput` as a proper macOS-native replacement.
@ayushh0110
Copy link
Copy Markdown
Owner

ayushh0110 commented Jun 2, 2026

hi @l984-451 thanks for the PR

couple of things before i merge:

  1. sys is already imported at the top of main.py (line 10), so the inline import sys as _sys isn't needed.

  2. the platform guard would be cleaner inside HotkeyListener.start() in capture/hotkey.py rather than patching main.py in two places — the rest of the codebase handles platform differences inside the module itself (see platform_support/__init__.py for the pattern). that way any future caller gets the guard automatically and main.py stays platform-agnostic.

something like:

# capture/hotkey.py - top of start()
def start(self):
    if self._running:
        return
    if sys.platform == "darwin":
        print("[Hotkey] Disabled on macOS (keyboard library lacks modifier+letter support). Use the dashboard.")
        return
    # ... existing registration code

.stop() already handles the no-start case (if not self._running: return), so no changes needed there.

  1. one thing i'm not sure about — does import keyboard at the top of hotkey.py itself trigger the Input Monitoring prompt on macOS even before start() is called? if so we might need to make that import conditional too. would appreciate if you could check since i don't have a mac.

thanks for the contribution 🙌

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