|
igraphic 0.2.0
Contrats graphiques chargeables : IGraphic2Module / IGraphic3Module
|
Keyboard interface. More...
#include <IKeyboard.hpp>
Public Member Functions | |
| virtual | ~IKeyboard () |
| Destroy the IKeyboard object. | |
| virtual std::vector< Keys > | whichKeyDown () 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. | |
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.
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.
Scan codes.
|
inlinevirtual |
Destroy the IKeyboard object.
|
pure virtual |
Check if the key is down.
| key |
|
pure virtual |
Check if the key is pressed.
| key |
|
pure virtual |
Check if the key is released.
| key |
|
pure virtual |
Check if the key is up.
| key |
|
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.