Bevy Archie - Rust / Bevy Controller Support Module

A comprehensive game controller support module for the Bevy engine, inspired by the RenPy Controller GUI project.
Controller Support Matrix
| Controller | Gyroscope | Touchpad | Adaptive Triggers | Rumble | Layout |
|---|---|---|---|---|---|
| Xbox 360 | 🔴 | 🔴 | 🔴 | ✅ | Xbox |
| Xbox One | 🔴 | 🔴 | 🔴 | ✅ | Xbox |
| Xbox Series X|S | 🔴 | 🔴 | 🔴 | ✅ | Xbox |
| PlayStation 3 | ✅ | 🔴 | 🔴 | ✅ | PlayStation |
| PlayStation 4 | ✅ | ✅ | 🔴 | ✅ | PlayStation |
| PlayStation 5 | ✅ | ✅ | ✅ | ✅ | PlayStation |
| Switch Pro | ✅ | 🔴 | 🔴 | ✅ | Nintendo |
| Switch 2 Pro | ✅ | 🔴 | 🔴 | ✅ | Nintendo |
| Switch Joy-Con | ✅ | 🔴 | 🔴 | ✅ | Nintendo |
| Steam Controller | ✅ | ✅ | 🔴 | ✅ | Xbox |
| Stadia | ✅ | 🔴 | 🔴 | ✅ | Xbox |
| Amazon Luna | 🔴 | 🔴 | 🔴 | ✅ | Xbox |
| 8BitDo M30 | 🔴 | 🔴 | 🔴 | ✅ | Sega |
| 8BitDo SN30 Pro | 🔴 | 🔴 | 🔴 | ✅ | Nintendo |
| HORI Fighting Cmd | 🔴 | 🔴 | 🔴 | ✅ | PlayStation |
| Generic | 🔶 | 🔶 | 🔴 | ✅ | Xbox |
Legend: ✅ Supported | 🔴 Hardware limitation | 🔶 Unknown (varies by device)
Note: Gyroscope, touchpad, and adaptive triggers require platform-specific implementations. See Advanced Features for details.
Version Compatibility
| bevy | bevy_archie |
|---|---|
| 0.18 | bevy-0.18 branch |
| 0.17 | 0.1.x (main) |
Features
Core Input System
- Input Device Detection: Automatically detect and switch between mouse, keyboard, and gamepad input
- Input Action Mapping: Abstract input actions with customizable bindings for gamepad, keyboard, and mouse
- Action State Tracking: Query pressed, just_pressed, just_released states and analog values for any action
- Per-Stick Settings: Independent sensitivity and inversion for left/right analog sticks
- Deadzone Configuration: Configurable stick deadzones with per-stick customization
Controller Support
- Controller Icon System: Asset-agnostic icon mapping system that adapts to controller type (Xbox, PlayStation, Nintendo, Steam, Stadia, Generic). Bring your own icon assets or use any compatible pack.
- Controller Profiles: Automatic detection and profile loading based on vendor/product IDs
- Multi-controller Support: Handle multiple connected controllers with player assignment
- Controller Layout Detection: Auto-detect and adapt UI to controller type
Advanced Input Features
- Actionlike Trait: Define custom action enums with the
Actionliketrait for type-safe input handling - Haptic Feedback: Rumble and vibration patterns (Constant, Pulse, Explosion, DamageTap, HeavyImpact, Engine, Heartbeat) - fully implemented
- Input Buffering: Record and analyze input sequences for fighting game-style combo detection
- Action Modifiers: Detect Tap, Hold, DoubleTap, LongPress, and Released events on actions
- Button Chords: Detect simultaneous button combinations with configurable clash resolution
- Virtual Input Composites: Combine buttons into virtual axes (
VirtualAxis,VirtualDPad,VirtualDPad3D) - Conditional Bindings: Context-aware actions that activate based on game state or custom conditions
- Input State Machine: Define state machines driven by input actions with automatic transitions
- Gyroscope Support: Motion controls for PS4/PS5/Switch/Stadia/Steam controllers - complete gesture detection and data structures, needs hardware driver integration (HID/SDL2). See ps5_dualsense_motion.rs and switch_pro_gyro.rs
- Touchpad Support: PS4/PS5/Steam touchpad input with multi-touch and gesture detection (swipe, pinch, tap) - complete gesture detection and data structures, needs hardware driver integration (HID/SDL2). See ps5_dualsense_motion.rs and steam_touchpad.rs
Multiplayer
- Player Assignment: Automatic or manual controller-to-player assignment (up to 4 players)
- Controller Ownership: Track which player owns which controller
- Hot-swapping: Handle controller disconnection and reassignment
UI & Configuration
- Controller Remapping: Allow players to remap controller buttons at runtime
- Virtual Keyboard: On-screen keyboard for controller-friendly text input
- Virtual Cursor: Gamepad-controlled cursor for mouse-based UI navigation
- Configuration Persistence: Save and load controller settings to/from JSON files
Developer Tools
- Input Debugging: Visualize input states, history, and analog values
- Input Recording: Record input sequences for testing and replay
- Input Playback: Play back recorded inputs for automated testing
- Input Mocking:
MockInputandMockInputPluginfor unit testing input-dependent systems - Build Helpers: Generate icon manifests and organize controller assets at build time
Mobile & Touch
- Touch Joystick: Virtual on-screen joysticks for mobile platforms with fixed or floating modes
Networking
- Input Synchronization:
ActionDiffandActionDiffBufferfor efficient network input sync with rollback support
Supported Controllers
- Xbox - Xbox 360, Xbox One, Xbox Series X|S controllers
- PlayStation - PS3, PS4, PS5 (DualShock 3, DualShock 4, and DualSense)
- Nintendo - Switch Pro Controller, Switch 2 Pro, Joy-Cons
- Steam - Steam Controller, Steam Deck
- Stadia - Google Stadia Controller (Bluetooth mode)
- Amazon Luna - Amazon Luna Controller (Xbox-style layout)
- 8BitDo - M30 (Sega-style), SN30 Pro (Nintendo-style)
- HORI - Fighting Commander, HORIPAD series
- Generic - Any other standard gamepad
Note: Stadia controllers must be switched to Bluetooth mode (a permanent one-time operation that was available until Dec 31, 2025). In Bluetooth mode, they function as standard Xbox-style gamepads.
Installation
Add to your Cargo.toml:
[]
= { = "path/to/bevy-archie" }
# Or with specific features:
= { = "path/to/bevy-archie", = ["full"] }
Quick Start
use *;
use *;
Action System
Define your game actions and bind them to controller buttons:
use *;
// Actions are predefined, but you can extend with custom actions
Remapping
Enable controller remapping in your settings menu:
Configuration
use *;
Virtual Cursor
Enable gamepad-controlled cursor for mouse-based UI:
use *;
use *;
Configuration Persistence
Save and load controller settings:
use *;
// Load config on startup
// Save config
// Custom path
Config files are saved to platform-specific directories:
- Linux:
~/.config/bevy_archie/controller.json - macOS:
~/Library/Application Support/bevy_archie/controller.json - Windows:
%APPDATA%\bevy_archie\controller.json
Examples
Bevy-archie includes several examples to help you get started:
Basic Examples
- basic_input.rs: Simple input handling
- controller_icons.rs: Display controller-specific icons
- remapping.rs: Runtime button remapping
- virtual_cursor.rs: Gamepad-controlled cursor
- config_persistence.rs: Save/load settings
Advanced Hardware Integration
These examples show how to integrate real hardware for gyro and touchpad:
-
ps5_dualsense_motion.rs: DualSense gyro + touchpad via hidapi
- Complete HID report parsing reference
- Both USB and Bluetooth modes
- Calibration and data injection patterns
-
switch_pro_gyro.rs: Switch Pro Controller gyro via SDL2
- Cross-platform gyro support
- Alternative: Direct HID approach
-
steam_touchpad.rs: Steam Deck/Steam Controller touchpad
- Steam Input API integration (recommended)
- Alternative: Direct HID for advanced users
Run examples with:
Supported Controller Layouts
- Xbox: Xbox 360, Xbox One, Xbox Series controllers
- PlayStation: DualShock 3/4, DualSense
- Nintendo: Joy-Con, Pro Controller, GameCube
- Steam: Steam Controller, Steam Deck
- Stadia: Google Stadia Controller (Bluetooth mode)
- Generic: Fallback for unrecognized controllers
Advanced Features
Haptic Feedback
Add rumble and vibration to your game:
use *;
// Available patterns:
// - Constant: Steady vibration
// - Pulse: Rhythmic pulsing
// - Explosion: Strong start with fade
// - DamageTap: Quick impact feel
// - HeavyImpact: Longer impact
// - Engine: Motor-like hum
// - Heartbeat: Pulse pattern
Input Buffering & Combos
Detect input sequences for fighting game mechanics:
use *;
Multiplayer Controller Management
Assign controllers to players:
use *;
Action Modifiers
Detect advanced input patterns:
use *;
// Configure modifier timings
PlayStation Touchpad
Handle touchpad input on DualShock 4 and DualSense:
use *;
Controller Profiles
Automatically detect controller models and load profiles:
use *;
Motion Controls (Gyroscope)
Access gyroscope and accelerometer data:
use *;
// Configure motion controls
Debug Tools
Visualize and record input for testing:
use *;
Virtual Input Composites
Combine multiple buttons into unified axes:
use *;
Button Chords
Detect simultaneous button presses:
use *;
Conditional Bindings
Make actions context-aware:
use *;
Input State Machine
Define states driven by input:
use *;
Input Mocking for Tests
Test input-dependent systems:
use *;
use *;
// Script a sequence of inputs
Touch Joystick (Mobile)
Add virtual joysticks for touch screens:
use *;
use *;
Network Input Sync
Synchronize input state across network:
use *;
use *;
Examples
Run the examples to see features in action:
# Basic input handling
# Controller icon display
# Button remapping UI
# Virtual cursor
# Config persistence
API Reference
SystemSets
bevy_archie provides the following system sets for ordering your systems:
Execution order: Detection → Actions → UI
Use these to order your systems relative to controller input processing:
app.add_systems;
Core Types
InputDeviceState
Tracks the currently active input device.
// Methods
;
;
;
;
ActionState
Query the state of game actions.
// Methods
;
;
;
; // 0.0-1.0 for analog
ActionMap
Map actions to input sources.
// Methods
;
;
;
;
;
;
GameAction
Predefined actions that can be customized.
// Methods
;
;
;
;
Configuration
ControllerConfig
Main configuration resource.
// Methods (for persistence)
;
;
;
;
Events (now Messages in Bevy 0.17)
All events are now Message types. Use MessageReader and MessageWriter:
InputDeviceChanged- Input device switchedGamepadConnected/GamepadDisconnected- Controller connectionVirtualCursorClick- Virtual cursor clickedRumbleRequest- Request haptic feedbackComboDetected- Input combo detectedModifiedActionEvent- Action modifier detectedTouchpadGestureEvent- Touchpad gestureMotionGestureDetected- Motion gestureControllerAssigned/ControllerUnassigned- Player assignmentControllerDetected- Controller model detectedStartRemapEvent/RemapEvent- Remapping eventsToggleInputDebug/RecordingCommand/PlaybackCommand- Debug commands
Platform Support
Haptic Feedback
Fully implemented using Bevy's native GamepadRumbleRequest. Works out of the box on all platforms that support rumble through gilrs.
Motion Controls
What's implemented: Complete gesture detection (shake, tilt, flick, roll), data structures (GyroData, AccelData), and event system.
What's needed: Hardware drivers to read sensor data from controllers. See the Hardware Integration Guide for detailed instructions.
Quick example (see ps5_dualsense_motion.rs for full code):
Touchpad
What's implemented: Complete gesture detection (swipe, pinch, tap, multi-touch), data structures (TouchpadData), and event system.
What's needed: Hardware drivers to read touchpad data from controllers. See the Hardware Integration Guide for detailed instructions.
Quick example (see ps5_dualsense_motion.rs for full code):
Hardware integration resources:
- 📘 Hardware Integration Guide - Complete guide with controller-specific details
- 🎮 PS5 DualSense Example - Both gyro and touchpad
- 🎮 Switch Pro Example - Gyro via SDL2
- 🎮 Steam Deck Example - Touchpad via Steam Input API
Migration from Bevy 0.16
Bevy 0.17 introduced a major change: Events are now Messages.
Key Changes
// Bevy 0.16
app.;
// Bevy 0.17
app.;
All events in bevy_archie have been migrated to Messages.
Testing
Running Tests
# Run all unit tests
# Run all tests including integration tests
# Run specific test module
# Run with all features enabled
Test Coverage
The project includes comprehensive unit and integration tests covering:
- Core Modules (
actions,config,detection): Input device detection, action mapping, configuration management - Icon System (
icons): Icon filename generation, platform-specific labels, asset loading - Integration Tests: Plugin initialization, resource management, end-to-end workflows
Coverage Goal: 80% code coverage across all modules. See docs/TEST_COVERAGE.md for coverage tools and analysis.
Test Structure
src/*/tests: Unit tests for each moduletests/integration_tests.rs: Integration tests for full plugin functionality.cargo/config.toml: Test configuration and aliases
For detailed coverage analysis instructions, see docs/TEST_COVERAGE.md.
Controller Icons
This library's icon system is asset-agnostic - it provides the infrastructure for loading and displaying controller-appropriate icons, but does not bundle icon assets in the crate to keep download size minimal.
Recommended Icon Pack
We recommend Mr. Breakfast's Free Prompts - a comprehensive CC0-licensed icon pack with 400+ PNG/SVG icons for Xbox, PlayStation, Nintendo Switch, Steam Deck, keyboard, and mouse.
Adding Icon Assets
-
Download the icon pack from itch.io
-
Extract to your project's assets folder:
your_game/ └── assets/ └── icons/ └── mrbreakfast/ ├── LICENSE └── png/ ├── xbox_a.png ├── ps_cross.png └── ... -
Configure the icon system:
Alternative Icon Packs
You can use any icon pack that follows standard naming conventions:
- Kenney Input Prompts (CC0)
- Xelu's Controllers & Keyboard Prompts (CC0)
- Custom artwork
Icon Naming Conventions
The system expects icons named according to platform conventions:
- Xbox:
xbox_a.png,xbox_b.png,xbox_lb.png,xbox_lt.png - PlayStation:
ps_cross.png,ps_circle.png,ps_l1.png,ps_l2.png - Nintendo:
switch_b.png,switch_a.png,switch_l.png,switch_zl.png - Generic:
left_stick.png,right_stick.png,dpad.png
Icon sizes are supported via suffixes: xbox_a_small.png (32x32), xbox_a.png (48x48), xbox_a_large.png (64x64).
If your icon pack uses different naming, create a thin wrapper or use symbolic links.
Credits
Inspired by the RenPy Controller GUI by Feniks.
Included Assets
- Mr. Breakfast's Free Prompts - Controller and keyboard input prompt icons by Mr. Breakfast. Over 400 PNG/SVG icons supporting Xbox, PlayStation, Nintendo Switch, Steam Deck, keyboard, and mouse. Licensed under CC0 1.0 Universal (Public Domain).
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.