# BUTTON

The `BUTTON` command waits for the user to press the physical push button on the top of the Packet Squirrel.  Optionally, it can use a specified timeout.

## Options

Calling `BUTTON` with no options will delay indefinitely until the user presses the physical button.

Calling `BUTTON` with a timeout value, in seconds, causes it to delay until the user presses the button *or* the timeout expires.

By default, `BUTTON` controls the LED to indicate that it is waiting for input; by setting the `NO_LED` environment variable first, `BUTTON` can be told to leave the LED alone:

```bash
NO_LED=1 BUTTON
```

## Return values

When called with a timeout, the `BUTTON` script will return a successful return code (0) when the button is pressed, and an unsuccessful result (non-0) if the timeout expires.

To learn how to write payloads which respond to return codes, check the [Advanced Bash](https://olddocs.hak5.org/packet-squirrel-mark-ii/advanced-payloads) section!

## Experimenting

You can experiment using the `BUTTON` command live, either in the Web Shell in the web UI, or via `ssh`!

<figure><img src="https://932701053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F520JUF2JxB2RMXztRVAV%2Fuploads%2FOfVjO2FgmNUq7ORT8C6j%2FScreenshot%20from%202023-02-13%2017-41-34.png?alt=media&#x26;token=a446ec71-c597-46c5-9879-49699f80dd1e" alt=""><figcaption><p>Using the BUTTON command in the Web Shell</p></figcaption></figure>

## Examples

```bash
#!/bin/bash

# Title: Basic demo one
#
# Description: A simple payload that waits for a button to be pressed

# Set the netmode to NAT, otherwise there is no connectivity at all
NETMODE NAT

# Set the LED to blinking cyan
LED C SINGLE

# Wait forever until the button is tapped
BUTTON

# Set the LED to blink blue in a triple pattern
LED B TRIPLE
```

A more advanced payload using conditionals to check if the button was pressed:

```bash
#!/bin/bash

# Title: More advanced buttons
#
# Description: React differently if the button was pressed or not

# Set the netmode to NAT, otherwise there is no connectivity at all
NETMODE NAT

# Set the LED to blinking cyan
LED C SINGLE

# Wait 3 seconds, set the LED depending on if the user presses the button
BUTTON 3 && {
    LED W SOLID
} || {
    LED R DOUBLE
}
```
