EMZETT.
Login

Gamepad and controller: How input devices for games work

In short: Gamepads send button presses and stick positions via USB or Bluetooth to the computer; operating systems and browsers provide them through standardised interfaces.

In more detail: A gamepad has digital buttons, analogue sticks, shoulder buttons and often analogue triggers. The controller reports its state many times a second, and the game reads it in the game loop.

In Depth

Structure and signals

  • Digital buttons: on or off (switch under rubber contacts).
  • Analogue sticks: two potentiometers or Hall sensors per axis, values from −1 to +1. Over time stick drift arises, where the stick reports values without being touched; Hall-effect sticks last longer.
  • Triggers: analogue values 0 to 1 (for example throttle and brake).
  • Rumble/haptics: motors or actuators for vibration; adaptive triggers on the PlayStation 5.
  • Extras: gyroscope, touchpad, LEDs.

Connection

USB (low latency, no battery needed), Bluetooth (wireless, somewhat more latency) or wireless dongle (2.4 GHz, often fastest). Standards: XInput (Xbox, Windows) and DirectInput; SDL and Steam Input unify different devices. On Linux the kernel recognises controllers through evdev.

Controllers in the browser (Gamepad API)

function loop() {
  const pad = navigator.getGamepads()[0];
  if (pad) {
    const x = pad.axes[0];        // left stick horizontal
    if (pad.buttons[0].pressed) { /* A button */ }
    if (Math.abs(x) > 0.15) move(x); // dead zone!
  }
  requestAnimationFrame(loop);
}

Important is a dead zone so that slight stick drift does not trigger movement. The gamepad often appears only after the first button press.

Buying and care

Mind compatibility (the Xbox layout is supported almost everywhere), battery life, build quality and replaceability of the sticks. Care: remove dust, do not dirty contacts, update firmware. For accessibility adaptive controllers and freely assignable buttons help.

See also: Game loop and delta time, Connecting Bluetooth, Game consoles