Skip to main content

mx4-haptic

Python mouse events and direct HID++ haptic control for the Logitech MX Master 4 on macOS. It does not use Logi Options+.

Install

python -m pip install mx4-haptic

Python 3.10 or newer is required. The package installs pynput for mouse events and hidapi on macOS for haptics.

Mouse buttons and scroll

MouseEvents reports the mouse events macOS makes available to the process. Events are global, and the library does not suppress them by default.

from mx4_haptic import MXMaster4


def on_button(event):
    print(event.phase, event.button, event.x, event.y)


def on_scroll(event):
    print(event.axis, event.dx, event.dy)


with MXMaster4(on_button=on_button, on_scroll=on_scroll) as mx4:
    mx4.join()  # Run until the listener is stopped or the process exits.

event.phase is "down" or "up". event.button uses left, right, and middle for standard buttons. macOS button numbers 3 and 4 map to x1 and x2; higher numbers use button_<number>. Scroll events carry raw dx and dy deltas; event.axis is horizontal, vertical, both, or none. macOS does not identify which physical wheel produced a delta, and Natural Scrolling can affect its sign.

The listener needs macOS Input Monitoring or Accessibility permission. These are OS-level events: a hardware control is available only if macOS exposes it as a mouse event. Raw HID++ button diversion is not included yet.

To listen without writing code:

mx4-haptic listen

Haptics

Haptic requests go directly to the mouse's HID++ feature 0x19B0. The current implementation supports a directly connected MX Master 4 over Bluetooth. It discovers waveform support and refuses to play an ID the device does not advertise.

from mx4_haptic import HapticController, Waveform


with HapticController() as haptics:
    print(haptics.get_state())
    print(haptics.get_supported_waveforms())
    haptics.play(Waveform.KNOCK)
    haptics.set_level(45)  # Writes the intensity to the mouse.

Playback does not change the mouse configuration. set_level() is an explicit, persistent device setting change and preserves the other configuration flags.

mx4-haptic haptics status
mx4-haptic haptics play KNOCK
mx4-haptic haptics level 45

Development

python -m venv .venv
source .venv/bin/activate
python -m pip install -e '.[dev]'
ruff check src tests
pytest
python -m build
python -m twine check dist/*

The tests do not require a mouse. Physical event delivery and haptic feedback require an MX Master 4 and macOS permissions.

Release and PyPI publishing

GitHub Actions runs lint, hardware-free tests, and package build checks. Publishing runs only when a GitHub Release is published. It uses PyPI Trusted Publishing (OIDC); no long-lived PyPI API token is stored in GitHub.

Before the first release, add a pending Trusted Publisher in your PyPI account. PyPI can create the project automatically on the first successful publish; a pending publisher does not reserve the name until then. Follow the PyPI setup guide and enter:

  • Project name: mx4-haptic
  • Owner: paveleu
  • Repository: mx4-haptic
  • Workflow: publish.yml
  • Environment: pypi

Then update the version in pyproject.toml and src/mx4_haptic/__init__.py, push the commit, and publish a GitHub Release for the matching tag, for example v0.1.2. The release workflow builds and checks the package, then publishes the built files to PyPI.

License

MIT. See LICENSE.

Metadata

Release files for mx4-haptic 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mx4-haptic 0.1.2
File Size Uploaded Provenance
mx4_haptic-0.1.2.tar.gz 14.9 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mx4-haptic 0.1.2
File Interpreter ABI Platform
mx4_haptic-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 27.3 kB

Release files / mx4_haptic-0.1.2.tar.gz

Download URL mx4_haptic-0.1.2.tar.gz
Size 14.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f3cf774dc8ad4c3cdc911d81b3d20cb620b0a118282a0830c2e1106fd75f0ecd
BLAKE2b-256 checksum
How to use checksums
dbc7e4616f7137c862beba20224eb2d9e5b893196f30edd6c17d92f0485b2b6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / mx4_haptic-0.1.2-py3-none-any.whl

Download URL mx4_haptic-0.1.2-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d99f8b8313fdaf17776b2661b5bbd399c0dcef0ad2288b7c78cf4981b6916e4
BLAKE2b-256 checksum
How to use checksums
0dc8f363450e6f15f15c07b5ec38699281be08e81fe0a8177409706ffaed1004
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Security for mx4-haptic 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mx4_haptic-0.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page