Skip to content

abstract struct SF::Event
inherits Struct #

Defines a system event and its parameters

SF::Event holds all the informations about a system event that just happened. Events are retrieved using the SF::Window.poll_event and SF::Window.wait_event functions.

A SF::Event instance contains the type of the event (mouse moved, key pressed, window closed, ...) as well as the details about this particular event. Please note that the event parameters are defined in a union, which means that only the member matching the type of the event will be properly filled; all other members will have undefined values and must not be read if the type of the event doesn't match. For example, if you received a KeyPressed event, then you must read the event.key member, all other members such as event.mouse_move or event.text will have undefined values.

Usage example:

while (event = window.poll_event)
  case event
  when SF::Event::Closed # Request for closing the window
  when SF::Event::KeyPressed # The escape key was pressed
    if event.code == SF::Keyboard::Escape
  when SF::Event::Resized # The window was resized
    do_something(event.width, event.height)
    # etc ...