using NativeEngine;
namespace Sandbox.UI;
///
/// Keyboard (and mouse) key press .
///
public record ButtonEvent
{
///
/// The button that triggered the event.
///
public string Button { get; }
///
/// Whether the button was pressed in, or release.
///
public bool Pressed { get; }
public int VirtualKey { get; }
///
/// The keyboard modifier keys that were held down at the moment the event triggered.
///
public KeyboardModifiers KeyboardModifiers { get; }
///
/// Whether Shift key was being held down at the time of the event.
///
public bool HasShift => KeyboardModifiers.Contains( KeyboardModifiers.Shift );
///
/// Whether Control key was being held down at the time of the event.
///
public bool HasCtrl => KeyboardModifiers.Contains( KeyboardModifiers.Ctrl );
///
/// Whether Alt key was being held down at the time of the event.
///
public bool HasAlt => KeyboardModifiers.Contains( KeyboardModifiers.Alt );
///
/// Set to to prevent the event from propagating to the parent panel.
///
public bool StopPropagation { get; set; }
internal ButtonEvent( ButtonCode button, bool pressed, KeyboardModifiers modifiers )
{
Button = InputEventQueue.NormalizeButtonName( button.ToString() );
Pressed = pressed;
VirtualKey = InputSystem.ButtonCodeToVirtualKey( button );
KeyboardModifiers = modifiers;
}
internal ButtonEvent( ButtonCode button, bool pressed )
{
Button = InputEventQueue.NormalizeButtonName( button.ToString() );
Pressed = pressed;
}
public override string ToString() => $"{Button} {(Pressed ? "pressed" : "released")}";
}