Handling user input

You can set how and which elements in your application react to user input. In Kanzi, to handle user input you can:

For these Kanzi nodes you do not have to create input manipulators manually, because they handle input by default:

Use triggers and actions to create interactions based on user input. See Using triggers.

Using input manipulators

Kanzi provides low and high-level access to input:

Kanzi provides input manipulators to enable gesture recognition for nodes in your Kanzi project. You can assign the manipulators through the API.

Kanzi provides these input manipulators:

InputManipulator is the base class for manipulators, and functions such as ClickManipulator::create and PanManipulator::create create input manipulators responsible for the corresponding gesture recognition.

When you create an input manipulator, to recognize the gesture, attach it to the node with Node::addInputManipulator. This attaches all the children of the node too.

Attached manipulator generates messages in response to user actions. Each manipulator uses messages to report different events during gesture recognition, such as PanManipulator::StartedMessage, PanManipulator::MovedMessage, PanManipulator::FinishedMessage for the pan manipulator and so on.

Defining which node receives user input

Since only one node receives user input at a time, when creating your user interface take special care how your application handles user input. For example, define whether a click is handled by the node in the front or by the one behind it.

Kanzi uses hit testing to determine the nodes that receive input. In practice, hit testing projects a ray from the camera towards the 3D scene based on the screen coordinates of the input event.

By default hit testing is disabled. To enable hit testing for a node, add the Hit Testable property, and enable it.

The first node from the Camera node whose bounding box is intersected and has the Hit Testable property enabled, receives the input, consumes the event and generates set actions, such as sending a click message.

For example, if you place two boxes so that BoxFront is in front of BoxRear and occludes it completely:

Setting the size of the input area

When you want to change the input area of a node use the Hit Testable Container property, which takes into consideration the layout size rather than the bounding volume of the node. Hit testing of all nodes is by default based on their layout size.

To define the size of the input area, add and enable the Hit Testable Container property in the node. If the node is not a button, you also have to add and enable the Hit Testable property.

For example, if you want to set the area of a button to be larger than the mesh in the button:

  1. Create a Button 3D, add and enable the Hit Testable Container property, and add an action to the Button: Click message.
  2. Create a Box inside the Button 3D, and add and set the Layout Height, Layout Width, and Layout Depth properties to the area where you want your button to respond to clicks or taps.
    The Button 3D receives the click input from the area set by the Layout Height, Layout Width, and Layout Depth properties of the Box inside the Button 3D.

See also

Handling keyboard input

Using the click manipulator

Using the long-press manipulator

Using the multi-click manipulator

Using the drag-and-drop manipulator

Using the pan manipulator

Using the pinch manipulator

Using the Button nodes

Using the Toggle Button nodes

List Box nodes

Using the List Box Item Container prefabs

Using the Scroll View nodes

Using the Slider nodes

Using triggers