KeyboardEvent
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.
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.
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) {
// 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.
| Value | Description |
|---|---|
| Pressed | Key transitioned to the down state. |
| Released | Key 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.
Key key {};type KeyboardEvent::Type
The interaction type for this event.
KeyboardEvent::Type type {};Functions
GetType() Event::Type virtual
Identifies this event as Event::Type::Keyboard.
Type vglx::KeyboardEvent::GetType() const override;