> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/flatredball/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/flatredball/api/flatredball/input/xbox360gamepad/buttondown.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
