# ButtonDown

### Introduction

The ButtonDown method returns whether a button is currently being held down. This will be false if the player is not pushing the button, and it will return true every frame that the button is pressed.

### Code Example - Checking Buttons

The following code shows how to perform logic if the player is holding the A or B buttons on the Xbox360GamePad:

Add the following using statements:

```csharp
using FlatRedBall.Input;
```

Later, perform the checks:

```csharp
 var gamepad = InputManager.Xbox360GamePads[0];
 if (gamepad.ButtonDown(Button.A))
 {
     // do something when the A button is down
 }
 if (gamepad.ButtonDown(Button.B))
 {
     // do something when the B button is down
 }
 if(gamePad.ButtonDown(ButtonPosition.FaceLeft))
 {
     // do somethign when the left button is down, which could be X or Y
 }
 
```

### Code Example - Checking DPad

The DPad on the Xbox360GamePad acts as four separate buttons. Therefore, each direction can be independently checked just like buttons. For example, the following code moves a character according to the left and right DPad.

```csharp
var gamePad = InputManager.Xbox360GamePads[0];
if(gamePad.ButtonDown(Xbox360GamePad.Button.DPadRight))
{
    PlayerInstance.XVelocity = 100;
}
else if(gamePad.ButtonDown(Xbox360GamePad.Button.DPadLeft))
{
    PlayerInstance.XVelocity = -100;
}
else
{
    PlayerInstance.XVelocity = 0;
}
```

### Code Example - Checking All Buttons

Buttons are represented by enumerations which can be looped through to check. The first enumeration value is 0, and the last value in the enumeration is Button.LeftStickAsDPadRight. Therefore, the following loop will check all buttons:

```csharp
for(int i = 0; i < (int)Xbox360GamePad.Button.LeftStickAsDPadRight + 1; i++)
{
  if(gamePad.ButtonDown( (Xbox360GamePad.Button)i))
  {
    // This button is down, do something
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flatredball.com/flatredball/api/flatredball/input/xbox360gamepad/buttondown.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
