Back to Content

GamepadButton: pressed property

files/en-us/web/api/gamepadbutton/pressed/index.md

latest603 B
Original Source

{{APIRef("Gamepad API")}}{{SecureContext_Header}}

The GamepadButton.pressed property of the {{domxref("GamepadButton")}} interface returns a boolean indicating whether the button is currently pressed (true) or unpressed (false).

Examples

js
let gp = navigator.getGamepads()[0]; // Get the first gamepad object

if (gp.buttons[0].pressed) {
  // respond to button being pressed
}

Value

A boolean value.

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also