Class SFML::Input
In: window/main.cpp
Parent: Object

The SFML::Input class provides a way to access the state of keys, mouse buttons, mouse position, joystick buttons and jostick axis.

SFML::Input provides the same informations as the event system, but these informations can be accessed at any time, which is more convenient in many situations.

For example, to move an entity you can decide to catch the SFML::Event::KeyPressed event on arrow keys. But if you do so, you will only receive one event when the key gets pressed (or repeated events if you activated this feature), thus the entity will not move smoothly. The best solution here is to use SFML::Input#isKeyDown so that you can update your entity‘s position at every iteration of your game loop, not only when you catch a KeyPressed event.

Note that instances of SFML::Input cannot be created directly, they must be retrieved from a window (SFML::Window) with the SFML::Window#input method.

Usage example:

  # Retrieve the input object attached to our window
  input = window.input

  # Move an entity according to the current keys state
  offset = 5.0 * window.frameTime # 5 pixels/sec
  entity.move( -offset, 0 ) if input.keyDown?( SFML::Key::Left )
  entity.move( offset, 0 )  if input.keyDown?( SFML::Key::Right )
  entity.move( 0, -offset ) if input.keyDown?( SFML::Key::Up )
  entity.move( 0,  offset ) if input.keyDown?( SFML::Key::Down )

Methods

Public Class methods

This will create a new input object. though it will not receive any updates of events. You should aquire an input object from the SFML::Window#input method.

Public Instance methods

The returned position is in the range [-100, 100], except the POV which is an angle and is thus defined in [0, 360].

The returned position is relative to the left border of the owner window.

The returned position is relative to the top border of the owner window.

Get the current state of a joystick button (pressed or released).

Get the current state of a key (pressed or released).

Get the current state of a mouse button (pressed or released).

joystickAxis(p1, p2)

Alias for getJoystickAxis

joystickButtonDown?(p1, p2)
joystick_axis(p1, p2)

Alias for getJoystickAxis

joystick_button_down?(p1, p2)
keyDown?(p1)

Alias for isKeyDown

key_down?(p1)

Alias for isKeyDown

mouseButtonDown?(p1)

Alias for isMouseButtonDown

mouseX()

Alias for getMouseX

mouseY()

Alias for getMouseY

mouse_button_down?(p1)

Alias for isMouseButtonDown

mouse_x()

Alias for getMouseX

mouse_y()

Alias for getMouseY

[Validate]