Event

sfml.window.Event
See theEvent companion object
enum Event

Defines a system event and its parameters.

Event holds all the informations about a system event that just happened.

Events are retrieved using the pollEvent function.

A Event instance contains the type of the event (mouse moved, key pressed, window closed, ...) as well as the details about this particular event.

import sfml.system.Vector2
val window: Window = ???
val doSomethingWithTheNewSize: Vector2[Int] => Unit = ???

for event <- window.pollEvent() do
   event match
       // Request for closing the window
       case Event.Closed() => window.close()

       // The escape key was pressed
       case Event.KeyPressed(Keyboard.Key.Escape, _, _, _, _, _) => window.close()

       // The window was resized
       case Event.Resized(size) => doSomethingWithTheNewSize(size)

       // etc...

       case _ => ()

Attributes

Companion
object
Graph
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Type members

Enum entries

final case class Closed()

Closed event subtype.

Closed event subtype.

Attributes

final case class FocusGained()

Gained focus event subtype

Gained focus event subtype

Attributes

final case class FocusLost()

Lost focus event subtype.

Lost focus event subtype.

Attributes

final case class KeyPressed(code: Key, scancode: Scan, alt: Boolean, control: Boolean, shift: Boolean, system: Boolean)

Key pressed event subtype.

Key pressed event subtype.

Value parameters

alt

Is the Alt key pressed?

code

Code of the key that has been pressed.

control

Is the Control key pressed?

scancode

Physical code of the key that has been pressed.

shift

Is the Shift key pressed?

system

Is the System key pressed?

Attributes

Companion
object
final case class KeyReleased(code: Key, scancode: Scan, alt: Boolean, control: Boolean, shift: Boolean, system: Boolean)

Key released event subtype.

Key released event subtype.

Value parameters

alt

Is the Alt key pressed?

code

Code of the key that has been released.

control

Is the Control key pressed?

scancode

Physical code of the key that has been released.

shift

Is the Shift key pressed?

system

Is the System key pressed?

Attributes

Companion
object
final case class MouseButtonPressed(button: Button, position: Vector2[Int])

Mouse button pressed event subtype.

Mouse button pressed event subtype.

Value parameters

button

Code of the button that has been pressed.

position

Position of the mouse pointer, relative to the top left of the owner window.

Attributes

Companion
object
final case class MouseButtonReleased(button: Button, position: Vector2[Int])

Mouse button released event subtype.

Mouse button released event subtype.

Value parameters

button

Code of the button that has been released.

position

Position of the mouse pointer, relative to the top left of the owner window.

Attributes

Companion
object
final case class MouseEntered()

Mouse entered event subtype.

Mouse entered event subtype.

Attributes

final case class MouseLeft()

Mouse left event subtype.

Mouse left event subtype.

Attributes

final case class MouseMoved(position: Vector2[Int])

Mouse move event subtype.

Mouse move event subtype.

Value parameters

position

Position of the mouse pointer, relative to the top left of the owner window.

Attributes

Companion
object
final case class MouseMovedRaw(delta: Vector2[Int])

Mouse move raw event subtype.

Mouse move raw event subtype.

Raw mouse input data comes unprocessed from the operating system hence "raw". While the MouseMoved position value is dependent on the screen resolution, raw data is not. If the physical mouse is moved too little to cause the screen cursor to move at least a single pixel, no MouseMoved event will be generated. In contrast, any movement information generated by the mouse independent of its sensor resolution will always generate a MouseMovedRaw event.

In addition to screen resolution independence, raw mouse data also does not have mouse acceleration or smoothing applied to it as MouseMoved does.

Raw mouse movement data is intended for controlling non-cursor movement, e.g. controlling the camera orientation in a first person view, whereas MouseMoved is intended primarily for controlling things related to the screen cursor hence the additional processing applied to it.

Currently, raw mouse input events will only be generated on Windows and Linux.

Value parameters

delta

Delta movement of the mouse since the last event.

Attributes

Companion
object
final case class MouseWheelScrolled(wheel: Wheel, delta: Float, position: Vector2[Int])

Mouse wheel scrolled event subtype.

Mouse wheel scrolled event subtype.

Value parameters

delta

Wheel offset (positive is up/left, negative is down/right). High-precision mice may use non-integral offsets.

position

Position of the mouse pointer, relative to the top left of the owner window.

wheel

Which wheel (for mice with multiple ones).

Attributes

Companion
object
final case class Resized(size: Vector2[Int])

Resized event subtype.

Resized event subtype.

Value parameters

size

New size, in pixels.

Attributes

Companion
object
final case class TextEntered(unicode: Int)

Text event subtype.

Text event subtype.

Value parameters

unicode

UTF-32 Unicode value of the character.

Attributes

Companion
object