igraphic 0.2.0
Contrats graphiques chargeables : IGraphic2Module / IGraphic3Module
Loading...
Searching...
No Matches
graphic::IKeyboard Interface Referenceabstract

Keyboard interface. More...

#include <IKeyboard.hpp>

Public Types

enum  Keys {
  KEY_UNKNOWN = -1 , KEY_ESCAPE , KEY_F1 , KEY_F2 ,
  KEY_F3 , KEY_F4 , KEY_F5 , KEY_F6 ,
  KEY_F7 , KEY_F8 , KEY_F9 , KEY_F10 ,
  KEY_F11 , KEY_F12 , KEY_1 , KEY_2 ,
  KEY_3 , KEY_4 , KEY_5 , KEY_6 ,
  KEY_7 , KEY_8 , KEY_9 , KEY_0 ,
  KEY_MINUS , KEY_EQUAL , KEY_BACKSPACE , KEY_TAB ,
  KEY_Q , KEY_W , KEY_E , KEY_R ,
  KEY_T , KEY_Y , KEY_U , KEY_I ,
  KEY_O , KEY_P , KEY_LEFT_BRACKET , KEY_RIGHT_BRACKET ,
  KEY_CAPS_LOCK , KEY_LEFT_CONTROL , KEY_A , KEY_S ,
  KEY_D , KEY_F , KEY_G , KEY_H ,
  KEY_J , KEY_K , KEY_L , KEY_SEMICOLON ,
  KEY_APOSTROPHE , KEY_BACKTICK , KEY_ENTER , KEY_LEFT_SHIFT ,
  KEY_BACKSLASH , KEY_Z , KEY_X , KEY_C ,
  KEY_V , KEY_B , KEY_N , KEY_M ,
  KEY_COMMA , KEY_PERIOD , KEY_SLASH , KEY_RIGHT_SHIFT ,
  KEY_LEFT_ALT , KEY_LEFT_SUPER , KEY_SPACE , KEY_RIGHT_ALT ,
  KEY_RIGHT_SUPER , KEY_RIGHT_CONTROL , KEY_PAD_0 , KEY_PAD_1 ,
  KEY_PAD_2 , KEY_PAD_3 , KEY_PAD_4 , KEY_PAD_5 ,
  KEY_PAD_6 , KEY_PAD_7 , KEY_PAD_8 , KEY_PAD_9 ,
  KEY_PAD_MINUS , KEY_PAD_PLUS , KEY_PAD_DOT , KEY_PAD_ENTER ,
  KEY_UP , KEY_DOWN , KEY_LEFT , KEY_RIGHT ,
  KEY_COUNT
}
 Scan codes. More...
 

Public Member Functions

virtual ~IKeyboard ()
 Destroy the IKeyboard object.
 
virtual std::vector< KeyswhichKeyDown () const =0
 Every key HELD right now - like isKeyDown, without having to name the key.
 
virtual bool isKeyPressed (Keys key) const =0
 Check if the key is pressed.
 
virtual bool isKeyReleased (Keys key) const =0
 Check if the key is released.
 
virtual bool isKeyDown (Keys key) const =0
 Check if the key is down.
 
virtual bool isKeyUp (Keys key) const =0
 Check if the key is up.
 

Detailed Description

Keyboard interface.

Four methods, two behaviours.

isKeyPressed / isKeyReleased are true for ONE FRAME only, the one where the key changes state. Holding a key does not re-trigger isKeyPressed, even when the OS sends key repeat.

isKeyDown / isKeyUp are true EVERY FRAME for as long as the key is held (or released).

For a key pressed on frame 3 and released on frame 6 :

key             ______/‾‾‾‾‾‾‾‾‾‾‾\______
frame            1   2   3   4   5   6   7

isKeyDown        0   0   1   1   1   0   0
isKeyUp          1   1   0   0   0   1   1
isKeyPressed     0   0   1   0   0   0   0
isKeyReleased    0   0   0   0   0   1   0

Hence the run / jump pair : isKeyDown(KEY_W) keeps moving while W is held, isKeyPressed(KEY_SPACE) jumps once. Jumping on isKeyDown jumps sixty times a second.

All four are readable ANYWHERE in the frame, on every vendor : the window drains its queue once in pollEvent() and folds it into state, so nothing has to be read at a particular moment.

while (window->isOpen()) {
if (window->pollEvent()) { // the frame's event pump
window->eventClose();
if (kb->isKeyPressed(KEY_SPACE)) // a front
jump();
}
if (kb->isKeyDown(KEY_W)) // a state, outside
walk();
window->beginDraw();
// ...
window->endDraw(); // end of frame
}
@ KEY_W
Definition IKeyboard.hpp:122
@ KEY_SPACE
Definition IKeyboard.hpp:168

The condition is an optimisation, not a rule : with no event the fronts are false anyway. It only holds for the fronts - isKeyDown, isKeyUp and whichKeyDown() are true across frames where nothing happened, so putting them inside would silently drop them on a vendor that has a queue and keep them on one that has not.

The boundary between two frames is endDraw(). A press + release inside the same frame is lost, on every vendor.

Modifiers are keys like any other : Shift+E is isKeyDown(KEY_LEFT_SHIFT) and isKeyPressed(KEY_E), composed by the caller.

Member Enumeration Documentation

◆ Keys

Scan codes.

Enumerator
KEY_UNKNOWN 
KEY_ESCAPE 

Line 0.

KEY_F1 
KEY_F2 
KEY_F3 
KEY_F4 
KEY_F5 
KEY_F6 
KEY_F7 
KEY_F8 
KEY_F9 
KEY_F10 
KEY_F11 
KEY_F12 
KEY_1 

Line 1.

KEY_2 
KEY_3 
KEY_4 
KEY_5 
KEY_6 
KEY_7 
KEY_8 
KEY_9 
KEY_0 
KEY_MINUS 
KEY_EQUAL 
KEY_BACKSPACE 
KEY_TAB 

Line 2.

KEY_Q 
KEY_W 
KEY_E 
KEY_R 
KEY_T 
KEY_Y 
KEY_U 
KEY_I 
KEY_O 
KEY_P 
KEY_LEFT_BRACKET 
KEY_RIGHT_BRACKET 
KEY_CAPS_LOCK 

Line 3.

KEY_LEFT_CONTROL 
KEY_A 
KEY_S 
KEY_D 
KEY_F 
KEY_G 
KEY_H 
KEY_J 
KEY_K 
KEY_L 
KEY_SEMICOLON 
KEY_APOSTROPHE 
KEY_BACKTICK 
KEY_ENTER 
KEY_LEFT_SHIFT 

Line 4.

KEY_BACKSLASH 
KEY_Z 
KEY_X 
KEY_C 
KEY_V 
KEY_B 
KEY_N 
KEY_M 
KEY_COMMA 
KEY_PERIOD 
KEY_SLASH 
KEY_RIGHT_SHIFT 
KEY_LEFT_ALT 

Line 5.

KEY_LEFT_SUPER 
KEY_SPACE 
KEY_RIGHT_ALT 
KEY_RIGHT_SUPER 
KEY_RIGHT_CONTROL 
KEY_PAD_0 

KEYPAD.

KEY_PAD_1 
KEY_PAD_2 
KEY_PAD_3 
KEY_PAD_4 
KEY_PAD_5 
KEY_PAD_6 
KEY_PAD_7 
KEY_PAD_8 
KEY_PAD_9 
KEY_PAD_MINUS 
KEY_PAD_PLUS 
KEY_PAD_DOT 
KEY_PAD_ENTER 
KEY_UP 

ARROWS.

KEY_DOWN 
KEY_LEFT 
KEY_RIGHT 
KEY_COUNT 

Constructor & Destructor Documentation

◆ ~IKeyboard()

virtual graphic::IKeyboard::~IKeyboard ( )
inlinevirtual

Destroy the IKeyboard object.

Member Function Documentation

◆ isKeyDown()

virtual bool graphic::IKeyboard::isKeyDown ( Keys  key) const
pure virtual

Check if the key is down.

Parameters
key
Returns
bool

◆ isKeyPressed()

virtual bool graphic::IKeyboard::isKeyPressed ( Keys  key) const
pure virtual

Check if the key is pressed.

Parameters
key
Returns
bool

◆ isKeyReleased()

virtual bool graphic::IKeyboard::isKeyReleased ( Keys  key) const
pure virtual

Check if the key is released.

Parameters
key
Returns
bool

◆ isKeyUp()

virtual bool graphic::IKeyboard::isKeyUp ( Keys  key) const
pure virtual

Check if the key is up.

Parameters
key
Returns
bool

◆ whichKeyDown()

virtual std::vector< Keys > graphic::IKeyboard::whichKeyDown ( ) const
pure virtual

Every key HELD right now - like isKeyDown, without having to name the key.

A held key stays in the list every frame. For a debug overlay, a state readout, chord detection.

Walks the whole keyboard : avoid in a hot loop, isKeyDown is a direct lookup.

Returns
std::vector<Keys>

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