> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dairy.foundation/llms.txt
> Use this file to discover all available pages before exploring further.

# Bindings

Bindings are how you attach commands to user inputs or other events.

Mercurial uses the `BoundBooleanSupplier` system to provide bindings, which is
a thin wrapper over
[EnhancedBooleanSupplier](/Core/enhancedsuppliers/enhanced_boolean_supplier).
Go read its documentation for more information.

Go look at gamepads for more information on the first line of these examples.

<CodeGroup>
  ```java Java theme={null}
  // we can set up commands to be run
  Mercurial.gamepad1().a()
  	// runs on the rising edge of button a
  	.onTrue(new Lambda("command-name"))
  	// runs on the falling edge of button a
  	.onFalse(new Lambda("command-name"))
  	// runs on the rising edge of button a, until the falling edge, then ends naturally
  	.whileTrue(new Lambda("command-name"))
  	// runs on the falling edge of button a, until the rising edge, then ends naturally
  	.whileFalse(new Lambda("command-name"))
  	// runs on the rising edge of button a, reschedules if it ends early, until the falling edge, then ends naturally
  	.untilFalse(new Lambda("command-name"))
  	// runs on the falling edge of button a, reschedules if it ends early, until the rising edge, then ends naturally
  	.untilTrue(new Lambda("command-name"))
  	// runs on the rising edge of button a, cancels on the next rising edge
  	.toggleTrue(new Lambda("command-name"))
  	// runs on the falling edge of button a, cancels on the next falling edge
  	.toggleFalse(new Lambda("command-name"))
  	// cancels on the rising edge of a
  	.cancelOnTrue(new Lambda("command-name"))
  	// cancels on the falling edge of a
  	.cancelOnFalse(new Lambda("command-name"));
  ```

  ```kt Kotlin theme={null}
  // we can set up commands to be run
  Mercurial.gamepad1.a
  	// runs on the rising edge of button a
  	.onTrue(Lambda("command-name"))
  	// runs on the falling edge of button a
  	.onFalse(Lambda("command-name"))
  	// runs on the rising edge of button a, until the falling edge, then ends naturally
  	.whileTrue(Lambda("command-name"))
  	// runs on the falling edge of button a, until the rising edge, then ends naturally
  	.whileFalse(Lambda("command-name"))
  	// runs on the rising edge of button a, reschedules if it ends early, until the falling edge, then ends naturally
  	.untilFalse(Lambda("command-name"))
  	// runs on the falling edge of button a, reschedules if it ends early, until the rising edge, then ends naturally
  	.untilTrue(Lambda("command-name"))
  	// runs on the rising edge of button a, cancels on the next rising edge
  	.toggleTrue(Lambda("command-name"))
  	// runs on the falling edge of button a, cancels on the next falling edge
  	.toggleFalse(Lambda("command-name"))
  	// cancels on the rising edge of a
  	.cancelOnTrue(Lambda("command-name"))
  	// cancels on the falling edge of a
  	.cancelOnFalse(Lambda("command-name"))
  ```
</CodeGroup>

A BoundBooleanSupplier can be easily built from a `BoundDoubleSupplier` which is
a thin wrapper over
[EnhancedDoubleSupplier](/Core/enhancedsuppliers/enhanced_numeric_supplier).
This is done by using the same conditional system built into
`EnhancedDoubleSuppliers`.

The Mercurial gamepads use these for sticks and triggers.

Both of these classes can be easily constructed:

<CodeGroup>
  ```java Java theme={null}
  new BoundBooleanSupplier(() -> true);
  // you can also wrap an EnhancedBooleanSupplier
  new BoundBooleanSupplier(Pasteurized.gamepad1().a());
  new BoundDoubleSupplier(() -> 0.0);
  // you can also wrap an EnhancedDoubleSupplier
  new BoundDoubleSupplier(Pasteurized.gamepad1().leftStickY());

  // conditional binding
  new BoundDoubleSupplier(() -> 0.0)
  	.conditionalBindState()
  	.greaterThan(10.0)
  	.bind()
  	.whileTrue(new Lambda("while-greater-than-10"));
  ```

  ```kt Kotlin theme={null}
  BoundBooleanSupplier { true }
  // you can also wrap an EnhancedBooleanSupplier
  BoundBooleanSupplier(Pasteurized.gamepad1.a)
  BoundDoubleSupplier { 0.0 }
  // you can also wrap an EnhancedDoubleSupplier
  BoundDoubleSupplier(Pasteurized.gamepad1.leftStickY)

  // conditional binding
  BoundDoubleSupplier { 0.0 }
  	.conditionalBindState()
  	.greaterThan(10.0)
  	.bind()
  	.whileTrue(Lambda("while-greater-than-10"))
  ```
</CodeGroup>

Cool! Bindings is pretty easy, consider building bindings to events both
internal and external to your system, like changes in internal state, or changes
in sensor values, to perform a larger amount of automation when it comes to
commands.
