Skip to content

KeyboardEvent

[Event](/reference/events/event) representing a keyboard key press or release.

[KeyboardEvent](/reference/events/keyboard_event) is dispatched when a key is pressed or released. Nodes can handle this event by overriding the OnKeyboardEvent() method. The event contains both the key involved and the type of interaction.

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::Sapce) {
        Jump();
        event->handled = true; // stop propagation
      }
    }
  }
};

INFO

Derives from Event and inherits all public properties and methods.

Properties

key Key

cpp
Key key

Key code associated with the event.

type KeyboardEvent::Type

cpp
KeyboardEvent::Type type

Keyboard event type.

Functions

GetType() EventType virtual

cpp
EventType vglx::KeyboardEvent::GetType() const override

Returns event type.

Released under the MIT License.