LogoLogo
  • Welcome
  • FAQ
  • GPU compatibility
  • Introduction
    • Getting Started
    • Rendering Meshes
    • Rendering Volumetric Data
    • Slice and Crop Volume Renderings
    • Attributes API
    • Node transformations
    • Bounding Boxes
  • Controls & Input Handling
    • Custom Controls
    • Gamepads
  • Advanced Topics
    • Custom Rendering Pipelines
    • Instancing
    • Rendering on Distributed Machines
    • Profiling
    • Volume Shaders and Uniforms
    • Network
Powered by GitBook
On this page
  • Adding a Behavior
  • Assigning Keys to Behaviors

Was this helpful?

Export as PDF
  1. Controls & Input Handling

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:

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:

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:

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

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

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

Does the same but for the "M" key.

PreviousBounding BoxesNextGamepads

Last updated 2 years ago

Was this helpful?

For more info on the available keys and combinations thereof see

InputTrigger syntax