Skip to content

VolumeUp / VolumeDown actions via CGEventPost(kCGHIDEventTap) don't change system volume on macOS #143

@rockets-cn

Description

@rockets-cn

Description

Binding VolumeUp / VolumeDown (or MuteVolume) to a mouse button does not change the system volume, even though the hook correctly detects the button press and reports:

button → executing bound action button=Back action=Volume Up
button → executing bound action button=Forward action=Volume Down

Root cause

The Action::VolumeUp / VolumeDown variants call macos::post_key(0x48/0x49, none) which posts CGEventCreateKeyboardEvent events to kCGHIDEventTap. On macOS, the volume keys (kVK_VolumeUp=0x48, kVK_VolumeDown=0x49, kVK_Mute=0x4A) are system-defined keys — they are not standard HID keyboard usages and CGEventPost to kCGHIDEventTap does not trigger the system volume handler.

Verified workaround

Using osascript to change volume works reliably:

osascript -e "set volume output volume ((output volume of (get volume settings)) + 7)"

Suggested fix

Volume (and potentially media) keys need to be posted as NSSystemDefined events (event type 14 / NSSystemDefined, subtype 8) rather than via CGEventCreateKeyboardEvent. The NX key types are:

  • NX_KEYTYPE_SOUND_UP = 0
  • NX_KEYTYPE_SOUND_DOWN = 1
  • NX_KEYTYPE_MUTE = 7

This is the same mechanism that post_media_key (line 828 of crates/openlogi-core/src/binding.rs) currently has as a stub — it also needs the NSSystemDefined approach.

Environment

  • macOS 26.5.1 (Sequoia)
  • OpenLogi v0.5.1
  • Logitech MX Master 3S (Bluetooth LE)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions