Milky2018/gamepad is a MoonBit gamepad input library for native targets. It provides gil-style events, state tracking, SDL controller mappings, input filters, force-feedback APIs, and a mock backend for tests.
moon add Milky2018/gamepadUse the native target for real device input:
moon test --target native
moon run --target nativeBest support today is on macOS. Linux and Windows are available on native targets as well.
- macOS native backend (
IOHIDManager) - Linux native backend (
evdev) - Windows native backend (
XInput) - Non-native targets for real device input
- Native gamepad discovery and hotplug events
Gilevent polling and blocking waits- Per-device state tracking through
GamepadandGamepadState - SDL controller mapping database support, including bundled mappings
- Input filters:
jitter,deadzone,axis_dpad_to_button,Repeat - Force-feedback APIs with platform-specific backend support
- Mock backend for deterministic tests
- Errors:
Gil::new()does not raise.GilBuilder::build()may raiseGilError. - Event time:
Event::time()is a millisecond timestamp. On native backends this comes from the OS clock; on the mock backend it is whatever you set inEvent::at(...). - Mappings (gil naming): Rust
gilre-exportsMappingDataasMapping. In this MoonBit port, the user-editable type isMappingData;Mappingis the parsed SDL mapping used byGil. - Filters: Compose filters with
filter_ev. If you write a custom filter, it must not turnSome(event)intoNone; to drop an event returnSome(event.drop()).
- macOS: not supported (will report
is_ff_supported = false). - Linux/Windows: supported when the backend/device supports rumble.
///|
test "quick start" {
let gil = Gil::new()
while true {
match gil.next_event() {
None => break
Some(ev) => ...
}
}
}///|
test "mock button press" {
let gil = GilBuilder::new()
.with_mock_gamepad_count(1)
.with_default_filters(false)
.build()
let id = @gamepad.GamepadId(0)
gil.insert_event(Event::at(id, ButtonPressed(South, BTN_SOUTH), 0L))
assert_true(gil.next_event() is Some(_))
}Codevalues are backend-specific raw input codes.- On macOS, some raw HID axes such as
RxandRymay need SDL mappings before they resolve to semanticAxisvalues. - On macOS,
PowerInfocurrently reportsUnknown. - On non-native targets, the package builds with a stub backend and does not provide real device events.
- Force-feedback repeat mode is exposed as
FfRepeat.
Apache-2.0.