Documentation de SFML 2.6.0

Attention: cette page se réfère à une ancienne version de SFML. Cliquez ici pour passer à la dernière version.
Loading...
Searching...
No Matches
sf::Event Class Reference

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

#include <SFML/Window/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  MouseWheelScrollEvent
 Mouse wheel events parameters (MouseWheelScrolled) More...
 
struct  SensorEvent
 Sensor event parameters (SensorChanged) More...
 
struct  SizeEvent
 Size events parameters (Resized) More...
 
struct  TextEvent
 Text event parameters (TextEntered) More...
 
struct  TouchEvent
 Touch events parameters (TouchBegan, TouchMoved, TouchEnded) More...
 

Public Types

enum  EventType {
  Closed , Resized , LostFocus , GainedFocus ,
  TextEntered , KeyPressed , KeyReleased , MouseWheelMoved ,
  MouseWheelScrolled , MouseButtonPressed , MouseButtonReleased , MouseMoved ,
  MouseEntered , MouseLeft , JoystickButtonPressed , JoystickButtonReleased ,
  JoystickMoved , JoystickConnected , JoystickDisconnected , TouchBegan ,
  TouchMoved , TouchEnded , SensorChanged , 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) More...
 
   KeyEvent   key
 Key event parameters (Event::KeyPressed, Event::KeyReleased) More...
 
   TextEvent   text
 Text event parameters (Event::TextEntered) More...
 
   MouseMoveEvent   mouseMove
 Mouse move event parameters (Event::MouseMoved) More...
 
   MouseButtonEvent   mouseButton
 Mouse button event parameters (Event::MouseButtonPressed, Event::MouseButtonReleased) More...
 
   MouseWheelEvent   mouseWheel
 Mouse wheel event parameters (Event::MouseWheelMoved) (deprecated) More...
 
   MouseWheelScrollEvent   mouseWheelScroll
 Mouse wheel event parameters (Event::MouseWheelScrolled) More...
 
   JoystickMoveEvent   joystickMove
 Joystick move event parameters (Event::JoystickMoved) More...
 
   JoystickButtonEvent   joystickButton
 Joystick button event parameters (Event::JoystickButtonPressed, Event::JoystickButtonReleased) More...
 
   JoystickConnectEvent   joystickConnect
 Joystick (dis)connect event parameters (Event::JoystickConnected, Event::JoystickDisconnected) More...
 
   TouchEvent   touch
 Touch events parameters (Event::TouchBegan, Event::TouchMoved, Event::TouchEnded) More...
 
   SensorEvent   sensor
 Sensor event parameters (Event::SensorChanged) More...
 
}; 
 

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 ...
}
Defines a system event and its parameters.
Definition: Event.hpp:45
KeyEvent key
Key event parameters (Event::KeyPressed, Event::KeyReleased)
Definition: Event.hpp:225
SizeEvent size
Size event parameters (Event::Resized)
Definition: Event.hpp:224
EventType type
Type of the event.
Definition: Event.hpp:220
@ Closed
The window requested to be closed (no data)
Definition: Event.hpp:190
@ Resized
The window was resized (data in event.size)
Definition: Event.hpp:191
@ KeyPressed
A key was pressed (data in event.key)
Definition: Event.hpp:195
@ Escape
The Escape key.
Definition: Keyboard.hpp:93
Keyboard::Key code
Code of the key that has been pressed.
Definition: Event.hpp:64
unsigned int width
New width, in pixels.
Definition: Event.hpp:54
unsigned int height
New height, in pixels.
Definition: Event.hpp:55

Definition at line 44 of file Event.hpp.

Member Enumeration Documentation

◆ EventType

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) (deprecated)

MouseWheelScrolled 

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

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)

TouchBegan 

A touch event began (data in event.touch)

TouchMoved 

A touch moved (data in event.touch)

TouchEnded 

A touch event ended (data in event.touch)

SensorChanged 

A sensor value changed (data in event.sensor)

Count 

Keep last – the total number of event types.

Definition at line 188 of file Event.hpp.

Member Data Documentation

◆ joystickButton

JoystickButtonEvent sf::Event::joystickButton

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

Definition at line 232 of file Event.hpp.

◆ joystickConnect

JoystickConnectEvent sf::Event::joystickConnect

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

Definition at line 233 of file Event.hpp.

◆ joystickMove

JoystickMoveEvent sf::Event::joystickMove

Joystick move event parameters (Event::JoystickMoved)

Definition at line 231 of file Event.hpp.

◆ key

KeyEvent sf::Event::key

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

Definition at line 225 of file Event.hpp.

◆ mouseButton

MouseButtonEvent sf::Event::mouseButton

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

Definition at line 228 of file Event.hpp.

◆ mouseMove

MouseMoveEvent sf::Event::mouseMove

Mouse move event parameters (Event::MouseMoved)

Definition at line 227 of file Event.hpp.

◆ mouseWheel

MouseWheelEvent sf::Event::mouseWheel

Mouse wheel event parameters (Event::MouseWheelMoved) (deprecated)

Definition at line 229 of file Event.hpp.

◆ mouseWheelScroll

MouseWheelScrollEvent sf::Event::mouseWheelScroll

Mouse wheel event parameters (Event::MouseWheelScrolled)

Definition at line 230 of file Event.hpp.

◆ sensor

SensorEvent sf::Event::sensor

Sensor event parameters (Event::SensorChanged)

Definition at line 235 of file Event.hpp.

◆ size

SizeEvent sf::Event::size

Size event parameters (Event::Resized)

Definition at line 224 of file Event.hpp.

◆ text

TextEvent sf::Event::text

Text event parameters (Event::TextEntered)

Definition at line 226 of file Event.hpp.

◆ touch

TouchEvent sf::Event::touch

Touch events parameters (Event::TouchBegan, Event::TouchMoved, Event::TouchEnded)

Definition at line 234 of file Event.hpp.

◆ type

EventType sf::Event::type

Type of the event.

Definition at line 220 of file Event.hpp.


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