SpaceMouse Driver
Cross-platform (Windows/macOS/Linux) driver for 3Dconnexion SpaceMouse and
compatible 3D-mouse devices. Accesses the device by raw HID capture
(through the hidapi crate), thus doesn't require
any additional software or driver to be installed. In particular, neither
3DxWare nor spacenavd is needed.
The crate was built for LibrePCB's SpaceMouse support, but usable by any application.
Example
use ;
use Duration;
let mut mouse = new?;
// Poll for the device, e.g. every second, until it is found.
while !mouse.connect
// Read events until the device is lost (e.g. unplugged).
loop
In addition to this synchronous API, this crate also offers a threaded API which
handles all the high-level logic and just calls your callback on any event. See
SpaceMouseThread
for details.
Ready-to-run programs are available in the examples directory:
Documentation
Available at docs.rs.
Why hidapi
This crate depends on the hidapi crate for
cross-platform HID access (hidraw on Linux, IOHIDManager on macOS,
hid.dll on Windows).
On Linux, the pure-Rust hidraw backend of hidapi is used (the
linux-native-basic-udev feature), so building and running this crate needs
neither libudev nor libusb; no -dev packages have to be installed. On
macOS and Windows, hidapi vendors a small amount of C source code (the
underlying hidapi C library) and compiles it as part of cargo build, via
the cc crate.
Linux Device Permissions
On Linux, hidraw device nodes are readable by root only by default. To
allow accessing a SpaceMouse as a normal user, install the provided udev
rule 70-spacemouse.rules:
&&
Then unplug and replug the device (or reboot) for the rule to take effect.
Status & Limitations
This library is in an early stage of development. The API is still subject to change, and only a small set of real devices has been tested so far. Feedback and bug reports are welcome.
Known limitations:
- Only the classic USB HID devices are supported. Newer wireless models may not work.
- Only translation and rotation events are reported. Button and other HID reports are silently ignored.
- Only the first compatible device found is used — there is no way to select a specific device yet.
- The
hidapifeature flags are hardcoded in this crate for now. For more control over the used HID access method, they would need to be exposed as crate features.
License
Library is licensed under MIT license, see LICENSE for details.