xarvh / elm-gamepad / Gamepad

You use the functions in this module to figure out, given a Gamepad object, the buttons and axis that the user is activating on that gamepad.

You can get the List of Gamepad objects from either the Gamepad.Simple module or the Gamepad.Advanced.

Gamepads


type alias Gamepad =
Private.Gamepad

A gamepad with a known mapping. You can use all control getters to query its state.

getIndex : Gamepad -> Basics.Int

Get the index of a gamepad. To match the LED indicator on XBOX gamepads, indices start from 1.

getIndex gamepad == 2

Digital input


type Digital
    = A
    | B
    | X
    | Y
    | Start
    | Back
    | Home
    | LeftStickPress
    | LeftStickUp
    | LeftStickDown
    | LeftStickLeft
    | LeftStickRight
    | LeftTrigger
    | LeftBumper
    | RightStickPress
    | RightStickUp
    | RightStickDown
    | RightStickLeft
    | RightStickRight
    | RightTrigger
    | RightBumper
    | DpadUp
    | DpadDown
    | DpadLeft
    | DpadRight

This type defines names for all available digital controls, whose state can be either True or False.

Since the names cover all controls defined the W3C draft, they are used also when when remapping the gamepad to declare which action should be bound to which control.

isPressed : Gamepad -> Digital -> Basics.Bool

Returns True if the button is currently being held down.

wasClicked : Gamepad -> Digital -> Basics.Bool

Returns True when a button changes from being up to being held down.

wasReleased : Gamepad -> Digital -> Basics.Bool

Returns True when a button changes from being held down to going back up.

dpadPosition : Gamepad -> { x : Basics.Int, y : Basics.Int }

X and Y coordinates (-1, 0 or +1) of the digital pad.

Analog input


type Analog
    = LeftX
    | LeftY
    | LeftTriggerAnalog
    | RightX
    | RightY
    | RightTriggerAnalog

Some controls can be accessed also as analog and this type defines special names for them.

value : Gamepad -> Analog -> Basics.Float

Returns a single value from an analog control.

leftStickPosition : Gamepad -> { x : Basics.Float, y : Basics.Float }

X and Y coordinates (-1 to +1) of the left stick.

rightStickPosition : Gamepad -> { x : Basics.Float, y : Basics.Float }

X and Y coordinates (-1 to +1) of the right stick.

Stuff you don't need

digitalToString : Digital -> String

This function is mostly used internally, you probably don't need it.