Unified input system handling keyboard, touchscreen, and gamepad input with haptic feedback support.
[heading: "Description"]Gamepad provides a unified input system that abstracts keyboard, touchscreen, and physical gamepad inputs into a consistent interface. It handles input detection, state tracking, vibration feedback, and provides signals for input events.
[heading: "Key Features"] [list] * Multi-platform input support * Touch control overlay for mobile * Input source auto-detection * Consistent button mapping * Signal-based event system * Input state tracking (held, pressed, released) * Haptic feedback/vibration support * Gamepad vibration actuator support [/list] [heading: "Constructor"] [table header] [ Parameter | Type | Description ] [ game | Phaser.Game | Game instance ] [ keyboardMap | Object | Custom keyboard mapping (optional) ] [ gamepadMap | Object | Custom gamepad mapping (optional) ] [/table] [heading: "Methods"] [table header] [ Method | Parameters | Description ] [ setupKeyboard | () | Configures keyboard input ] [ setupGamepad | () | Configures gamepad input ] [ setupTouch | () | Sets up touch controls ] [ setupInputDetection | () | Sets up input source detection ] [ detectInputSource | (source) | Detects last input source ] [ updateTouchControlsVisibility | () | Shows/hides touch controls based on input ] [ handleTouchStart | (e) | Handles touch start events ] [ handleTouchMove | (e) | Handles touch move events ] [ handleTouchEnd | (e) | Handles touch end events ] [ getButtonFromTouch | (touch) | Gets button from touch position ] [ update | () | Updates input states and dispatches signals ] [ updateButtonStates | () | Calculates pressed/released states ] [ releaseAll | () | Releases all buttons ] [ press | (key) | Simulates button press ] [ isTouchControlled | (key) | Checks if key is touch-controlled ] [ getDirection | () | Gets normalized direction vector (-1 to 1) ] [ vibrate | (duration) | Triggers haptic feedback vibration ] [ reset | () | Resets all input states ] [ destroy | () | Cleans up input system ] [/table] [heading: "Properties"] [table header] [ Property | Type | Description ] [ game | Phaser.Game | Game instance reference ] [ keys | Array | Available input keys ['up','down','left','right','a','b','select','start'] ] [ held | Object | Current held state for each key ] [ pressed | Object | Pressed this frame for each key ] [ released | Object | Released this frame for each key ] [ lastInputSource | String | Last detected input source ('keyboard','gamepad','touch','none') ] [ activeTouches | Map | Active touch points ] [ signals | Object | Phaser signals for input events ] [/table] [heading: "Input Keys"] [table header] [ Key | Description | Keyboard (Default) | Gamepad (Default) ] [ up | Up direction | UP, J, B | D-pad Up (12) ] [ down | Down direction | DOWN, F, V | D-pad Down (13) ] [ left | Left direction | LEFT, D, C | D-pad Left (14) ] [ right | Right direction | RIGHT, K, N | D-pad Right (15) ] [ a | Confirm / Right | Z | Button B (1) ] [ b | Cancel / Down | X | Button A (0) ] [ select | Select / Toggle | SPACEBAR | Select/Back (8) ] [ start | Start / Pause | ENTER | Start (9) ] [/table] [heading: "Signals"] [table header] [ Signal | Description ] [ pressed.[key] | Fired when specific key is pressed ] [ released.[key] | Fired when specific key is released ] [ pressed.any | Fired when any key is pressed ] [ released.any | Fired when any key is released ] [/table] [heading: "Vibration Support"]The vibrate method attempts vibration based on the last input source:
[table header] [ Input Source | Vibration Method ] [ touch | navigator.vibrate() (Cordova only) ] [ gamepad | Gamepad vibrationActuator.playEffect() ] [ keyboard | No vibration (silent) ] [/table] [heading: "Vibration Intensities"] [table header] [ Constant | Value | Use Case ] [ REGULAR_VIBRATION_INTENSITY | 75ms | Regular note hits ] [ WEAK_VIBRATION_INTENSITY | 50ms | Roll taps, light feedback ] [ STRONG_VIBRATION_INTENSITY | 50ms | Strong feedback ] [/table] [heading: "Example Usage"] [codeblock javascript] // Check input states if (gamepad.pressed.a) { console.log("A button pressed!"); } if (gamepad.held.up) { console.log("Moving up"); } // Get direction const dir = gamepad.getDirection(); // Vibrate controller gamepad.vibrate(100); // Listen to signals gamepad.signals.pressed.a.add(() => { console.log("A pressed via signal"); }); [/codeblock] [footer: "© Retora 2026"]