# Custom Controls

User inputs are handled by the `InputHandler,` which is part of `SceneryBase` and `Hubable`. Adding inputs can be done in an overwrite of the `inputSetup` method of `SceneryBase`. First a `Behavior` needs to be added before a key can be assigned.

## Adding a Behavior

A behavior defines an action which is executed when the corresponding keys are pressed. There are currently the following base behaviors from which can be inherited: `ClickBehavior`, `DragBehavior`, `ScrollBehavior`.

In most cases a `ClickBehavior` is used. Example:

```kotlin
val helloClick = object : ClickBehaviour {
    val output = "Hello World"

    override fun click(x: Int, y: Int) {
        logger.info(output + "at $x and $y")
    }
}
```

In cases where the `x` and `y` screen positions of the cursor are not needed, they are just ignored. Adding a behavior to the `InputHandler` is straightforward:

```kotlin
inputHandler?.addBehaviour("hello_click", helloClick)
```

`inputHandler` should be available from an overwrite of the `inputSetup` method.

## Assigning Keys to Behaviors

Assigning keys to a behavior works in a similar fashion:

```kotlin
inputHandler?.addKeyBinding("hello_click", "button1")
```

This code assigned the earlier added behavior to the first mouse button.

```kotlin
inputHandler?.addKeyBinding("hello_click", "M")
```

Does the same but for the "M" key.

For more info on the available keys and combinations thereof see [InputTrigger syntax](https://github.com/scijava/ui-behaviour/wiki/InputTrigger-syntax)


---

# 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.scenery.graphics/scenery/controls-and-input-handling/custom-controls.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.
