Input & Interaction

Project DVN

This document describes input & interaction using DVN.

Contents


Mouse

You can capture mouse input on a component using the following functions.

void onMouseButtonDown(MouseButtonEventHandler handler, bool ignoreIntersection = false);
void onMouseButtonUp(MouseButtonEventHandler handler, bool ignoreIntersection = false);
void onMouseMove(MouseMoveEventHandler handler);

Example:

component.onMouseButtonUp(new MouseButtonEventHandler((b,p) {
    if (b != MouseButton.left) return;

    // Do stuff ...
}));

MouseButton enum:

/// Enumeration of mouse buttons.
enum MouseButton
{
  /// The left mouse button
  left,
  /// The right mouse button
  right,
  /// The middle (wheel) mouse button
  middle,
  /// The first extra mouse button
  extraButton1,
  /// The second extra mouse button
  extraButton2,
}

Keyboard

You can capture keyboard input on a component using the following functions.

void onKeyboardDown(KeyboardEventHandler handler, bool ignoreFocus = false);
void onKeyboardUp(KeyboardEventHandler handler, bool ignoreFocus = false);

Example:

component.onKeyboardUp(new KeyboardEventHandler((k) {
    if (k != KeyboardKey.LControl) return;

    // Do stuff ...
}));

KeyboardKey enum:

/// Enumeration of keyboard keys.
enum KeyboardKey
{
  /// Unhandled key
  unknown = -1,
  /// The A key
  a = 0,
  /// The B key
  b,
  /// The C key
  c,
  /// The D key
  d,
  /// The E key
  e,
  /// The F key
  f,
  /// The G key
  g,
  /// The H key
  h,
  /// The I key
  i,
  /// The J key
  j,
  /// The K key
  k,
  /// The L key
  l,
  /// The M key
  m,
  /// The N key
  n,
  /// The O key
  o,
  /// The P key
  p,
  /// The Q key
  q,
  /// The R key
  r,
  /// The S key
  s,
  /// The T key
  t,
  /// The U key
  u,
  /// The V key
  v,
  /// The W key
  w,
  /// The X key
  x,
  /// The Y key
  y,
  /// The Z key
  z,
  /// The 0 key
  num0,
  /// The 1 key
  num1,
  /// The 2 key
  num2,
  /// The 3 key
  num3,
  /// The 4 key
  num4,
  /// The 5 key
  num5,
  /// The 6 key
  num6,
  /// The 7 key
  num7,
  /// The 8 key
  num8,
  /// The 9 key
  num9,
  /// The Escape key
  escape,
  /// The left Control key
  LControl,
  /// The left Shift key
  LShift,
  /// The left Alt key
  LAlt,
  /// The left OS specific key: window (Windows and Linux), apple (MacOS X), ...
  LSystem,
  /// The right Control key
  RControl,
  /// The right Shift key
  RShift,
  /// The right Alt key
  RAlt,
  /// The right OS specific key: window (Windows and Linux), apple (MacOS X), ...
  RSystem,
  /// The Menu key
  menu,
  /// The [ key
  LBracket,
  /// The ] key
  RBracket,
  /// The ; key
  semiColon,
  /// The , key
  comma,
  /// The . key
  period,
  /// The ' key
  quote,
  /// The / key
  slash,
  /// The \ key
  backSlash,
  /// The ~ key
  tilde,
  /// The = key
  equal,
  /// The - key
  dash,
  /// The Space key
  space,
  /// The Return key
  returnKey,
  /// The Backspace key
  backSpace,
  /// The Tabulation key
  tab,
  /// The Page up key
  pageUp,
  /// The Page down key
  pageDown,
  /// The End key
  end,

Text Input

You can capture text input using the following function.

void onTextInput(TextInputEventHandler handler, bool ignoreFocus = false);

Example:

component.onTextInput(new TextInputEventHandler((c,s) {
    if (s == "s")
    {
        // Do stuff on "s"
    }
}));

Hotkeys

DVN has the following hotkeys by default.

  • CTRL: Finish text or advance to next scene.
  • SPACE: Finish text or advance to next scene.
  • S: Take screenshot and place it in the gallery folder.

You can make custom hotkeys by capturing the overlay component from the following event.

void renderGameViewOverplayEnd(Panel overlay);

Example:

public override void renderGameViewOverplayEnd(Panel overlay)
{
    overlay.onTextInput(new TextInputEventHandler((c,s) {
        if (s == "q" || s == "Q") // Quit the game when someone presses q
        {
            getApplication().stop();
        }
    }));
}