Documentation of SFML 2.3.1

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

Give access to the real-time state of the keyboard. More...

#include <Keyboard.hpp>

Public Types

enum  Key {
  Unknown = -1, A = 0, B, C,
  D, E, F, G,
  H, I, J, K,
  L, M, N, O,
  P, Q, R, S,
  T, U, V, W,
  X, Y, Z, Num0,
  Num1, Num2, Num3, Num4,
  Num5, Num6, Num7, Num8,
  Num9, Escape, LControl, LShift,
  LAlt, LSystem, RControl, RShift,
  RAlt, RSystem, Menu, LBracket,
  RBracket, SemiColon, Comma, Period,
  Quote, Slash, BackSlash, Tilde,
  Equal, Dash, Space, Return,
  BackSpace, Tab, PageUp, PageDown,
  End, Home, Insert, Delete,
  Add, Subtract, Multiply, Divide,
  Left, Right, Up, Down,
  Numpad0, Numpad1, Numpad2, Numpad3,
  Numpad4, Numpad5, Numpad6, Numpad7,
  Numpad8, Numpad9, F1, F2,
  F3, F4, F5, F6,
  F7, F8, F9, F10,
  F11, F12, F13, F14,
  F15, Pause, KeyCount
}
 Key codes. More...
 

Static Public Member Functions

static bool isKeyPressed (Key key)
 Check if a key is pressed. More...
 
static void setVirtualKeyboardVisible (bool visible)
 Show or hide the virtual keyboard. More...
 

Detailed Description

Give access to the real-time state of the keyboard.

sf::Keyboard provides an interface to the state of the keyboard.

It only contains static functions (a single keyboard is assumed), so it's not meant to be instantiated.

This class allows users to query the keyboard state at any time and directly, without having to deal with a window and its events. Compared to the KeyPressed and KeyReleased events, sf::Keyboard can retrieve the state of a key at any time (you don't need to store and update a boolean on your side in order to know if a key is pressed or released), and you always get the real state of the keyboard, even if keys are pressed or released when your window is out of focus and no event is triggered.

Usage example:

{
// move left...
}
{
// move right...
}
{
// quit...
}
See also
sf::Joystick, sf::Mouse, sf::Touch

Definition at line 40 of file Keyboard.hpp.

Member Enumeration Documentation

Key codes.

Enumerator
Unknown 

Unhandled key.

The A key.

The B key.

The C key.

The D key.

The E key.

The F key.

The G key.

The H key.

The I key.

The J key.

The K key.

The L key.

The M key.

The N key.

The O key.

The P key.

The Q key.

The R key.

The S key.

The T key.

The U key.

The V key.

The W key.

The X key.

The Y key.

The Z key.

Num0 

The 0 key.

Num1 

The 1 key.

Num2 

The 2 key.

Num3 

The 3 key.

Num4 

The 4 key.

Num5 

The 5 key.

Num6 

The 6 key.

Num7 

The 7 key.

Num8 

The 8 key.

Num9 

The 9 key.

Escape 

The Escape key.

LControl 

The left Control key.

LShift 

The left Shift key.

LAlt 

The left Alt key.

LSystem 

The left OS specific key: window (Windows and Linux), apple (MacOS X), ...

RControl 

The right Control key.

RShift 

The right Shift key.

RAlt 

The right Alt key.

RSystem 

The right OS specific key: window (Windows and Linux), apple (MacOS X), ...

Menu 

The Menu key.

LBracket 

The [ key.

RBracket 

The ] key.

SemiColon 

The ; key.

Comma 

The , key.

Period 

The . key.

Quote 

The ' key.

Slash 

The / key.

BackSlash 

The \ key.

Tilde 

The ~ key.

Equal 

The = key.

Dash 

The - key.

Space 

The Space key.

Return 

The Return key.

BackSpace 

The Backspace key.

Tab 

The Tabulation key.

PageUp 

The Page up key.

PageDown 

The Page down key.

End 

The End key.

Home 

The Home key.

Insert 

The Insert key.

Delete 

The Delete key.

Add 

The + key.

Subtract 

The - key.

Multiply 

The * key.

Divide 

The / key.

Left 

Left arrow.

Right 

Right arrow.

Up 

Up arrow.

Down 

Down arrow.

Numpad0 

The numpad 0 key.

Numpad1 

The numpad 1 key.

Numpad2 

The numpad 2 key.

Numpad3 

The numpad 3 key.

Numpad4 

The numpad 4 key.

Numpad5 

The numpad 5 key.

Numpad6 

The numpad 6 key.

Numpad7 

The numpad 7 key.

Numpad8 

The numpad 8 key.

Numpad9 

The numpad 9 key.

F1 

The F1 key.

F2 

The F2 key.

F3 

The F3 key.

F4 

The F4 key.

F5 

The F5 key.

F6 

The F6 key.

F7 

The F7 key.

F8 

The F8 key.

F9 

The F9 key.

F10 

The F10 key.

F11 

The F11 key.

F12 

The F12 key.

F13 

The F13 key.

F14 

The F14 key.

F15 

The F15 key.

Pause 

The Pause key.

KeyCount 

Keep last – the total number of keyboard keys.

Definition at line 48 of file Keyboard.hpp.

Member Function Documentation

static bool sf::Keyboard::isKeyPressed ( Key  key)
static

Check if a key is pressed.

Parameters
keyKey to check
Returns
True if the key is pressed, false otherwise
static void sf::Keyboard::setVirtualKeyboardVisible ( bool  visible)
static

Show or hide the virtual keyboard.

Warning: the virtual keyboard is not supported on all systems. It will typically be implemented on mobile OSes (Android, iOS) but not on desktop OSes (Windows, Linux, ...).

If the virtual keyboard is not available, this function does nothing.

Parameters
visibleTrue to show, false to hide

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