Skip to content

KeyboardEvent ​

Represents a keyboard input event.

A keyboard event is dispatched when a key is pressed or released. It extends the base Event with data specific to keyboard input: the interaction type and the key code.

Keyboard events are dispatched through the Scene hierarchy where nodes can override the Node::OnKeyboardEvent handler and optionally mark the event as handled. When handled is set to true the event stops propagating to other nodes.

cpp
class MyNode : public vglx::Node {
public:
  auto OnKeyboardEvent(vglx::KeyboardEvent* event) -> void override {
    if (event->type == vglx::KeyboardEvent::Type::Pressed) {
      if (event->key == vglx::Key::Space) {
        // Do something...
        event->handled = true; // stop propagation
      }
    }
  }
};

INFO

Derives from Event and inherits all public properties and methods.

Types ​

KeyboardEvent::Type enum ​

Enumerates all keyboard event types.

Distinguishes between an initial press and a release. Engines that support key-repeat should surface repeat behavior at a higher layer, leaving this enum to represent the physical transitions only.

ValueDescription
PressedKey transitioned to the down state.
ReleasedKey transitioned to the up state.

Properties ​

key Key ​

Key code associated with the event.

Identifies which key triggered the event using the key enumeration. Refer to the source code for enum details.

cpp
Key key {};

The interaction type for this event.

cpp
KeyboardEvent::Type type {};

Functions ​

GetType() Event::Type virtual ​

Identifies this event as Event::Type::Keyboard.

cpp
Type vglx::KeyboardEvent::GetType() const override;

Released under the MIT License.