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 is the button name reported by macOS, such as left, right, middle, x1, or x2. 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, push the commit, and publish a GitHub Release for the matching tag, for example v0.1.0. 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.0

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.0
File Size Uploaded Provenance
mx4_haptic-0.1.0.tar.gz 12.2 kB With provenance Details

Built distribution (wheel)

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

Total release size: 23.7 kB

Release files / mx4_haptic-0.1.0.tar.gz

Download URL mx4_haptic-0.1.0.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b512096eaa8ea59d0bda7a540917631c36617ceceed898236797ee2bce492f43
BLAKE2b-256 checksum
How to use checksums
50a7017329e116f409b72ecd7cb9646cfe5dce16a0a9c8d05608eac7273ca366
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 25, 2026.

Transparency log

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

Download URL mx4_haptic-0.1.0-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
17e2b6f5647849e970f302a4183f982ee789c01e44dcbb6501cddfb01bff1a11
BLAKE2b-256 checksum
How to use checksums
845f80e839acfdda7af0a063f683ba95b042aead4375c0a02290d628b6c638b8
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 25, 2026.

Transparency log

Security for mx4-haptic 0.1.0

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.0.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 25, 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.0 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