Skip to content

Interface Modules꞉ Key

Zach Kinstner edited this page Nov 2, 2016 · 2 revisions

The Hoverkey interface provides a standard computer-keyboard layout, including sections for the number pad, arrow keys, and function keys. The sections, layouts, and individual keys can all be moved, changed, disabled, and/or customized.

The interface is composed of rectangular-shaped items and layouts. It provides interface-level event handlers, functional "Shift" and "Caps Lock" keys, and a script that can pass the keyboard input into a Unity InputField.

Hoverkey with Leap Motion 📷 Using the Hoverkey interface with Leap Motion hands

Overview

Location

The "Key" input module is contained in the /Assets/Hover/InterfaceModules/Key folder.

Installation

Use a "builder" component to generate this interface in your scene:

  1. Create an empty GameObject named Hoverkey.
  2. Add the HoverkeyBuilder component to Hoverkey.
    1. Modify the properties, if necessary.
    2. Click the "Build Interface" button.
  3. Modify the properties, if necessary, within the newly-generated components.

Reference

See the Hover.InputModules.Key namespace for technical reference, and /Assets/HoverExamples/Scenes/InterfaceModules-Key.unity for an example scene.

Tutorials

Hide Keyboard Section

In many scenarios, you may not need a complete keyboard layout. To hide and disable a keyboard section:

  1. Select any immediate child of the main Hoverkey object (for example, Hoverkey/Arrows).
    1. Disable the GameObject. The section will disappear, and will not be included in any interactions or events.
    2. Optional: Delete the GameObject.

New Item

Each keyboard section of the Hoverkey interface is contained within a HoverLayoutRectRow layout. To add a new item to a keyboard section:

  1. Choose a section GameObject, or event make a new one.
  2. Create an item, called MyItem, as a child of the section GameObject (see Getting Started for instructions).
  3. Add the HoverShapeRect component to MyItem
  4. Add the HoverkeyItemLabels component to MyItem
    1. Set its properties according to the desired key type.
  5. Find the HoverItemDataX component of MyItem, where X is the item type (for example, HoverItemDataSelector).
    1. Open the "Events" foldout section.
    2. Add an "On Selected Event" that points to HoverkeyInterface.HandleItemSelected().

Keyboard Input

The items within the keyboard sections all broadcast their selection events to their parent Hoverkey interface. The interface provides event handlers (via the HoverkeyInterface component) to listen for these events directly.

The interface also provides a component that collects the input as a string, and can optionally pass this input to a Unity InputField. This component handles various scenarios, including the effects of "Shift" and "Caps Lock" keys, reacting to control keys like "Enter" and "Backspace", and navigation with the arrow keys. To use this component:

  1. Find the HoverkeyTextInput component (attached to the main Hoverkey object).
    1. Use the "Text Input" property (via code) to read the user input.
    2. Set the "Input Field" property to the desired InputField reference.
Clone this wiki locally