SFML 3.0.2
Loading...
Searching...
No Matches
Classes | Public Member Functions | Friends | List of all members
sf::Event Class Reference
Window module

Defines a system event and its parameters. More...

`#include <SFML/Window/Event.hpp>`

## Classes
struct | Closed
| Closed event subtype. More...
struct | FocusGained
| Gained focus event subtype. More...
struct | FocusLost
| Lost focus event subtype. More...
struct | JoystickButtonPressed
| Joystick button pressed event subtype. More...
struct | JoystickButtonReleased
| Joystick button released event subtype. More...
struct | JoystickConnected
| Joystick connected event subtype. More...
struct | JoystickDisconnected
| Joystick disconnected event subtype. More...
struct | JoystickMoved
| Joystick axis move event subtype. More...
struct | KeyPressed
| Key pressed event subtype. More...
struct | KeyReleased
| Key released event subtype. More...
struct | MouseButtonPressed
| Mouse button pressed event subtype. More...
struct | MouseButtonReleased
| Mouse button released event subtype. More...
struct | MouseEntered
| Mouse entered event subtype. More...
struct | MouseLeft
| Mouse left event subtype. More...
struct | MouseMoved
| Mouse move event subtype. More...
struct | MouseMovedRaw
| Mouse move raw event subtype. More...
struct | MouseWheelScrolled
| Mouse wheel scrolled event subtype. More...
struct | Resized
| Resized event subtype. More...
struct | SensorChanged
| Sensor event subtype. More...
struct | TextEntered
| Text event subtype. More...
struct | TouchBegan
| Touch began event subtype. More...
struct | TouchEnded
| Touch ended event subtype. More...
struct | TouchMoved
| Touch moved event subtype. More...

## Public Member Functions
template<typename TEventSubtype>
| Event (const TEventSubtype &eventSubtype)
| Construct from a given sf::Event subtype.
template<typename TEventSubtype>
bool | is () const
| Check current event subtype.
template<typename TEventSubtype>
const TEventSubtype * | getIf () const
| Attempt to get specified event subtype.
template<typename Visitor>
decltype(auto) | visit (Visitor &&visitor) const
| Apply a visitor to the event.

## Friends
class | WindowBase

## Detailed Description

Defines a system event and its parameters.

sf::Event holds all the information about a system event that just happened.

Events are retrieved using the sf::Window::pollEvent and sf::Window::waitEvent functions.

A sf::Event instance contains the subtype of the event (mouse moved, key pressed, window closed, ...) as well as the details about this particular event. Each event corresponds to a different subtype struct which contains the data required to process that event.

Event subtypes are event types belonging to sf::Event, such as sf::Event::Closed or sf::Event::MouseMoved.

The way to access the current active event subtype is via sf::Event::getIf. This member function returns the address of the event subtype struct if the event subtype matches the active event, otherwise it returns nullptr.

sf::Event::is is used to check the active event subtype without actually reading any of the corresponding event data.

while (const std::optional event = window.pollEvent())
{
// Window closed or escape key pressed: exit
if (event->is<sf::Event::Closed>() ||
(event->is<sf::Event::KeyPressed>() &&
event->getIf<sf::Event::KeyPressed>()->code == sf::Keyboard::Key::Escape))
window.close();
// The window was resized
if (const auto* resized = event->getIf<sf::Event::Resized>())
doSomethingWithTheNewSize(resized->size);
// etc ...
}
sf::Keyboard::Key::Escape
@ Escape
The Escape key.
Definition Keyboard.hpp:90
sf::Event::Closed
Closed event subtype.
Definition Event.hpp:55
sf::Event::KeyPressed
Key pressed event subtype.
Definition Event.hpp:97
sf::Event::KeyPressed::code
Keyboard::Key code
Code of the key that has been pressed.
Definition Event.hpp:98
sf::Event::Resized
Resized event subtype.
Definition Event.hpp:63

Definition at line 47 of file Event.hpp.

## Constructor & Destructor Documentation

## ◆ Event()

template<typename TEventSubtype>

sf::Event::Event | ( | const TEventSubtype & | eventSubtype | ) |

Construct from a given sf::Event subtype.

Template Parameters

  `TEventSubtype` | Type of event subtype used to construct the event

Parameters

  eventSubtype | Event subtype instance used to construct the event

## Member Function Documentation

## ◆ getIf()

template<typename TEventSubtype>

const TEventSubtype * sf::Event::getIf | ( |  | ) | const
| nodiscard

Attempt to get specified event subtype.

Template Parameters

  `TEventSubtype` | Type of the desired event subtype

Returns
  Address of current event subtype, otherwise nullptr

## ◆ is()

template<typename TEventSubtype>

bool sf::Event::is | ( |  | ) | const
| nodiscard

Check current event subtype.

Template Parameters

  `TEventSubtype` | Type of the event subtype to check against

Returns
  true if the current event subtype matches given template parameter

## ◆ visit()

template<typename Visitor>

decltype(auto) sf::Event::visit | ( | Visitor && | visitor | ) | const

Apply a visitor to the event.

Parameters

  visitor | The visitor to apply

Returns
  The result of applying the visitor to the event

## Friends And Related Symbol Documentation

## ◆ WindowBase

friend class WindowBase
| friend

Definition at line 383 of file Event.hpp.

The documentation for this class was generated from the following file:

- Event.hpp