Documentation of SFML 2.0

Warning: this page refers to an old version of SFML. Click here to switch to the latest version.
sf::Event Class Reference

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

#include <Event.hpp>


struct  JoystickButtonEvent
 Joystick buttons events parameters (JoystickButtonPressed, JoystickButtonReleased) More...
struct  JoystickConnectEvent
 Joystick connection events parameters (JoystickConnected, JoystickDisconnected) More...
struct  JoystickMoveEvent
 Joystick axis move event parameters (JoystickMoved) More...
struct  KeyEvent
 Keyboard event parameters (KeyPressed, KeyReleased) More...
struct  MouseButtonEvent
 Mouse buttons events parameters (MouseButtonPressed, MouseButtonReleased) More...
struct  MouseMoveEvent
 Mouse move event parameters (MouseMoved) More...
struct  MouseWheelEvent
 Mouse wheel events parameters (MouseWheelMoved) More...
struct  SizeEvent
 Size events parameters (Resized) More...
struct  TextEvent
 Text event parameters (TextEntered) More...

Public Types

enum  EventType {
 Enumeration of the different types of events. More...

Public Attributes

EventType type
 Type of the event.
union {
   SizeEvent   size
 Size event parameters (Event::Resized)
   KeyEvent   key
 Key event parameters (Event::KeyPressed, Event::KeyReleased)
   TextEvent   text
 Text event parameters (Event::TextEntered)
   MouseMoveEvent   mouseMove
 Mouse move event parameters (Event::MouseMoved)
   MouseButtonEvent   mouseButton
 Mouse button event parameters (Event::MouseButtonPressed, Event::MouseButtonReleased)
   MouseWheelEvent   mouseWheel
 Mouse wheel event parameters (Event::MouseWheelMoved)
   JoystickMoveEvent   joystickMove
 Joystick move event parameters (Event::JoystickMoved)
   JoystickButtonEvent   joystickButton
 Joystick button event parameters (Event::JoystickButtonPressed, Event::JoystickButtonReleased)
   JoystickConnectEvent   joystickConnect
 Joystick (dis)connect event parameters (Event::JoystickConnected, Event::JoystickDisconnected)

Detailed Description

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::pollEvent and sf::Window::waitEvent 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.MouseMove or event.text will have undefined values.

Usage example:

sf::Event event;
while (window.pollEvent(event))
// Request for closing the window
if (event.type == sf::Event::Closed)
// The escape key was pressed
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
// The window was resized
if (event.type == sf::Event::Resized)
doSomethingWithTheNewSize(event.size.width, event.size.height);
// etc ...

Definition at line 43 of file Event.hpp.

Member Enumeration Documentation

Enumeration of the different types of events.


The window requested to be closed (no data)


The window was resized (data in event.size)


The window lost the focus (no data)


The window gained the focus (no data)


A character was entered (data in event.text)


A key was pressed (data in event.key)


A key was released (data in event.key)


The mouse wheel was scrolled (data in event.mouseWheel)


A mouse button was pressed (data in event.mouseButton)


A mouse button was released (data in event.mouseButton)


The mouse cursor moved (data in event.mouseMove)


The mouse cursor entered the area of the window (no data)


The mouse cursor left the area of the window (no data)


A joystick button was pressed (data in event.joystickButton)


A joystick button was released (data in event.joystickButton)


The joystick moved along an axis (data in event.joystickMove)


A joystick was connected (data in event.joystickConnect)


A joystick was disconnected (data in event.joystickConnect)


Keep last – the total number of event types.

Definition at line 148 of file Event.hpp.

Member Data Documentation

JoystickButtonEvent sf::Event::joystickButton

Joystick button event parameters (Event::JoystickButtonPressed, Event::JoystickButtonReleased)

Definition at line 186 of file Event.hpp.

JoystickConnectEvent sf::Event::joystickConnect

Joystick (dis)connect event parameters (Event::JoystickConnected, Event::JoystickDisconnected)

Definition at line 187 of file Event.hpp.

JoystickMoveEvent sf::Event::joystickMove

Joystick move event parameters (Event::JoystickMoved)

Definition at line 185 of file Event.hpp.

KeyEvent sf::Event::key

Key event parameters (Event::KeyPressed, Event::KeyReleased)

Definition at line 180 of file Event.hpp.

MouseButtonEvent sf::Event::mouseButton

Mouse button event parameters (Event::MouseButtonPressed, Event::MouseButtonReleased)

Definition at line 183 of file Event.hpp.

MouseMoveEvent sf::Event::mouseMove

Mouse move event parameters (Event::MouseMoved)

Definition at line 182 of file Event.hpp.

MouseWheelEvent sf::Event::mouseWheel

Mouse wheel event parameters (Event::MouseWheelMoved)

Definition at line 184 of file Event.hpp.

SizeEvent sf::Event::size

Size event parameters (Event::Resized)

Definition at line 179 of file Event.hpp.

TextEvent sf::Event::text

Text event parameters (Event::TextEntered)

Definition at line 181 of file Event.hpp.

EventType sf::Event::type

Type of the event.

Definition at line 175 of file Event.hpp.

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