Documentation of SFML 2.1

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>

Classes

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 {
  Closed,
  Resized,
  LostFocus,
  GainedFocus,
  TextEntered,
  KeyPressed,
  KeyReleased,
  MouseWheelMoved,
  MouseButtonPressed,
  MouseButtonReleased,
  MouseMoved,
  MouseEntered,
  MouseLeft,
  JoystickButtonPressed,
  JoystickButtonReleased,
  JoystickMoved,
  JoystickConnected,
  JoystickDisconnected,
  Count
}
 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)
window.close();
// The escape key was pressed
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
window.close();
// 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.

Enumerator:
Closed 

The window requested to be closed (no data)

Resized 

The window was resized (data in event.size)

LostFocus 

The window lost the focus (no data)

GainedFocus 

The window gained the focus (no data)

TextEntered 

A character was entered (data in event.text)

KeyPressed 

A key was pressed (data in event.key)

KeyReleased 

A key was released (data in event.key)

MouseWheelMoved 

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

MouseButtonPressed 

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

MouseButtonReleased 

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

MouseMoved 

The mouse cursor moved (data in event.mouseMove)

MouseEntered 

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

MouseLeft 

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

JoystickButtonPressed 

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

JoystickButtonReleased 

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

JoystickMoved 

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

JoystickConnected 

A joystick was connected (data in event.joystickConnect)

JoystickDisconnected 

A joystick was disconnected (data in event.joystickConnect)

Count 

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: