fltk.events

FLTK Event Types and Query Functions

This module provides typed event structures and functions for querying the current event state. It builds on the low-level Event enum to provide a more D-friendly interface for event handling.

Event Types:

  • MouseEvent: Mouse position, button, and click information
  • KeyEvent: Key code, text, and modifier state
  • FocusEvent: Focus gained/lost information
  • ResizeEvent: Window/widget resize information

Example:

// Query current mouse position
auto x = eventX();
auto y = eventY();

// Get current event as typed structure
auto mouse = currentMouseEvent();
writefln("Mouse at (%d, %d), button %d", mouse.x, mouse.y, mouse.button);

Authors

Dejan Lekić

License

BSD-3-Clause

Types 6

Mouse event information.

Contains all relevant information about a mouse event including position, button state, and click count.

Fields
int xX coordinate relative to window
int yY coordinate relative to window
int rootXX coordinate relative to root window
int rootYY coordinate relative to root window
int buttonMouse button that triggered the event (1=left, 2=middle, 3=right)
int clicksNumber of clicks (for double-click detection)
uint stateModifier keys held during event
Event eventThe event type
Methods
bool isLeftButton() const @safe nothrow @nogcChecks if the left mouse button is pressed.
bool isMiddleButton() const @safe nothrow @nogcChecks if the middle mouse button is pressed.
bool isRightButton() const @safe nothrow @nogcChecks if the right mouse button is pressed.
bool isDoubleClick() const @safe nothrow @nogcChecks if this is a double-click.
bool isShiftHeld() const @safe nothrow @nogcChecks if Shift is held.
bool isCtrlHeld() const @safe nothrow @nogcChecks if Ctrl is held.
bool isAltHeld() const @safe nothrow @nogcChecks if Alt is held.
structKeyEvent

Keyboard event information.

Contains key code, text representation, and modifier state.

Fields
uint keyThe key code
string textText representation of the key (for printable characters)
uint stateModifier keys held during event
Event eventThe event type (KEYDOWN or KEYUP)
Methods
bool isKeyDown() const @safe nothrow @nogcChecks if this is a key down event.
bool isKeyUp() const @safe nothrow @nogcChecks if this is a key up event.
bool isShiftHeld() const @safe nothrow @nogcChecks if Shift is held.
bool isCtrlHeld() const @safe nothrow @nogcChecks if Ctrl is held.
bool isAltHeld() const @safe nothrow @nogcChecks if Alt is held.
bool isEnter() const @safe nothrow @nogcChecks if this is the Enter key.
bool isEscape() const @safe nothrow @nogcChecks if this is the Escape key.
bool isTab() const @safe nothrow @nogcChecks if this is the Tab key.

Focus event information.

Fields
Event eventThe event type (FOCUS or UNFOCUS)
Methods
bool gained() const @safe nothrow @nogcChecks if focus was gained.
bool lost() const @safe nothrow @nogcChecks if focus was lost.

Resize event information.

Fields
int widthNew width
int heightNew height
int oldWidthPrevious width (if available)
int oldHeightPrevious height (if available)
Methods
bool sizeChanged() const @safe nothrow @nogcChecks if the size actually changed.

Mouse position information.

Fields
int x
int y

Compose result information.

Fields
bool complete
int bytesToDelete

Functions 23

fnint eventX() nothrow @nogcGets the current event's X coordinate.
fnint eventY() nothrow @nogcGets the current event's Y coordinate.
fnint eventRootX() nothrow @nogcGets the current event's root X coordinate.
fnint eventRootY() nothrow @nogcGets the current event's root Y coordinate.
fnint eventButton() nothrow @nogcGets the mouse button that triggered the current event.
fnint eventClicks() nothrow @nogcGets the number of clicks for the current event.
fnuint eventKey() nothrow @nogcGets the key code for the current keyboard event.
fnuint eventState() nothrow @nogcGets the modifier state for the current event.
fnstring eventText() nothrowGets the text for the current keyboard event.
fnint eventLength() nothrow @nogcGets the length of the event text.
fnMouseEvent currentMouseEvent() nothrow @nogcCreates a MouseEvent from the current FLTK event state.
fnKeyEvent currentKeyEvent() nothrowCreates a KeyEvent from the current FLTK event state.
fnbool isMouseEvent(Event e) @safe nothrow @nogcChecks if the given event is a mouse event.
fnbool isKeyboardEvent(Event e) @safe nothrow @nogcChecks if the given event is a keyboard event.
fnbool isFocusEvent(Event e) @safe nothrow @nogcChecks if the given event is a focus event.
fnint eventOriginalKey() nothrow @nogc @trustedGets the original key code before any keyboard remapping.
fnbool eventIsClick() nothrow @nogc @trustedChecks if the current event is a click (not a drag).
fnvoid eventSetIsClick(bool isClick) nothrow @nogc @trustedSets the click flag for the current event.
fnbool eventInsideRect(int x, int y, int w, int h) nothrow @nogc @trustedChecks if the current event is inside a rectangle.
fnbool getKey(int key) nothrow @nogc @trustedChecks if a key is currently pressed.
fnMousePosition getMouse() nothrow @nogc @trustedGets the current mouse position on screen.
fnComposeResult compose() nothrow @nogc @trustedHandles compose/dead key sequences.
fnvoid composeReset() nothrow @nogc @trustedResets the compose state.