class EE::Window::Input

Overview

The basic input class. For mouse and keyboard. More…

#include <input.hpp>

class Input {
public:
    // typedefs

    typedef std::function<void(InputEvent*)> InputCallback;

    // construction

    virtual ~Input();

    // methods

    virtual void update() = 0;
    virtual void waitEvent(const Time& timeout = Time::Zero) = 0;
    virtual bool grabInput() = 0;
    virtual void grabInput(const bool& Grab) = 0;
    virtual void injectMousePos(const Uint16& x, const Uint16& y) = 0;
    virtual Vector2i queryMousePos() = 0;
    virtual void captureMouse(const bool& capture) = 0;
    virtual bool isMouseCaptured() const = 0;
    virtual std::string getKeyName(const Keycode& keycode) const = 0;
    virtual Keycode getKeyFromName(const std::string& keycode) const = 0;
    virtual std::string getScancodeName(const Scancode& scancode) const = 0;
    virtual Scancode getScancodeFromName(const std::string& scancode) const = 0;
    virtual Keycode getKeyFromScancode(const Scancode& scancode) const = 0;
    virtual Scancode getScancodeFromKey(const Keycode& scancode) const = 0;
    bool isKeyUp(const Keycode& Key);
    bool isKeyDown(const Keycode& Key);
    bool isScancodeUp(const Scancode& scancode);
    bool isScancodeDown(const Scancode& scancode);
    void injectKeyUp(const Keycode& Key);
    void injectScancodeDown(const Scancode& scancode);
    void injectScancodeUp(const Scancode& scancode);
    void injectMousePos(const Vector2i& Pos);
    void injectButtonPress(const Uint32& Button);
    void injectButtonRelease(const Uint32& Button);
    bool isLeftControlPressed() const;
    bool isRightControlPressed() const;
    bool isControlPressed() const;
    bool isKeyModPressed() const;
    bool isLeftShiftPressed() const;
    bool isRightShiftPressed() const;
    bool isShiftPressed() const;
    bool isAltPressed() const;
    bool isLeftAltPressed() const;
    bool isAltGrPressed() const;
    bool isMetaPressed() const;
    bool isMouseLeftPressed() const;
    bool isMouseRightPressed() const;
    bool isMouseMiddlePressed() const;
    bool mouseLeftClicked() const;
    bool mouseRightClicked() const;
    bool mouseMiddleClicked() const;
    bool mouseLeftDoubleClicked() const;
    bool mouseRightDoubleClicked() const;
    bool mouseMiddleDoubleClicked() const;
    bool mouseWheelScrolledUp() const;
    bool mouseWheelScrolledDown() const;
    Uint32 pushCallback(const InputCallback& cb);
    void popCallback(const Uint32& CallbackId);
    Vector2i getMousePos() const;
    void setMousePos(const Vector2i& Pos);
    Vector2f getMousePosFromView(const View& View);
    void setMouseSpeed(const Float& Speed);
    const Float& getMouseSpeed() const;
    const Uint32& getLastPressTrigger() const;
    const Uint32& getPressTrigger() const;
    const Uint32& getReleaseTrigger() const;
    const Uint32& getClickTrigger() const;
    const Uint32& getDoubleClickTrigger() const;
    const Time& getDoubleClickInterval() const;
    void setDoubleClickInterval(const Time& Interval);
    void cleanStates();
    void sendEvent(InputEvent* Event);
    JoystickManager* getJoystickManager() const;
    Uint32 getFingerCount();
    InputFinger* getFingerIndex(const Uint32& Index);
    InputFinger* getFinger(const Int64& fingerId);
    std::vector<InputFinger*> getFingersDown();
    std::vector<InputFinger*> getFingersWasDown();
    const Uint32& getModState() const;
    void processEvent(InputEvent* Event);
    const Uint64& getEventsSentId() const;
    Uint32 getSanitizedModState() const;
    bool isModState(const Uint32& state) const;
    Time getElapsedSinceLastEvent() const;
    Time getElapsedSinceLastKeyboardEvent() const;
    Time getElapsedSinceLastMouseEvent() const;
    Time getElapsedSinceLastKeyboardOrMouseEvent() const;
};

Detailed Documentation

The basic input class. For mouse and keyboard.

Methods

virtual void update() = 0

Update the Input

virtual void waitEvent(const Time& timeout = Time::Zero) = 0

If timeout is zero waits indefinitely for the next available event otherwise waits until the specified timeout for the next available event.

virtual bool grabInput() = 0

Returns:

If the mouse and keyboard are grabed.

virtual void grabInput(const bool& Grab) = 0

Grab or Ungrab the mouse and keyboard.

virtual void injectMousePos(const Uint16& x, const Uint16& y) = 0

Inject the mouse position given

virtual Vector2i queryMousePos() = 0

Gets the current mouse position relative to the focus window

virtual void captureMouse(const bool& capture) = 0

Capturing enables your app to obtain mouse events globally, instead of just within your window. Not all video targets support this function. When capturing is enabled, the current window will get all mouse events, but unlike relative mode, no change is made to the cursor and it is not restrained to your window.

virtual bool isMouseCaptured() const = 0

Returns:

If mouse is captured.

virtual std::string getKeyName(const Keycode& keycode) const = 0

Returns:

Get the key name.

virtual Keycode getKeyFromName(const std::string& keycode) const = 0

Returns:

The corresponding keycode from a name.

virtual std::string getScancodeName(const Scancode& scancode) const = 0

Returns:

Get the scancode name.

virtual Scancode getScancodeFromName(const std::string& scancode) const = 0

Returns:

The corresponding scancode from a name.

virtual Keycode getKeyFromScancode(const Scancode& scancode) const = 0

Returns:

The key from the scancode.

virtual Scancode getScancodeFromKey(const Keycode& scancode) const = 0

Returns:

The scancode from a key.

bool isKeyUp(const Keycode& Key)

Returns:

If keyboard key was released.

bool isKeyDown(const Keycode& Key)

Returns:

If keyboard key is pressed.

bool isScancodeUp(const Scancode& scancode)

Returns:

If scancode was released.

bool isScancodeDown(const Scancode& scancode)

Returns:

If scancode it’s pressed.

void injectKeyUp(const Keycode& Key)

Inject the key state of a key as key up or released.

void injectScancodeDown(const Scancode& scancode)

Inject the scancode state of a scancode as pressed.

void injectScancodeUp(const Scancode& scancode)

Inject the key state of a key as released.

void injectMousePos(const Vector2i& Pos)

Inject the mouse position given

void injectButtonPress(const Uint32& Button)

Inject the mouse button as pressed

void injectButtonRelease(const Uint32& Button)

Inject the mouse button as released

bool isLeftControlPressed() const

Returns:

If the left Control Key is pressed

bool isRightControlPressed() const

Returns:

If the right Control Key is pressed

bool isControlPressed() const

Returns:

If the Control Key is pressed

bool isKeyModPressed() const

Returns:

If the default key modifier is pressed

bool isLeftShiftPressed() const

Returns:

If the left Shift Key is pressed

bool isRightShiftPressed() const

Returns:

If the right Shift Key is pressed

bool isShiftPressed() const

Returns:

If the Shift Key is pressed

bool isAltPressed() const

Returns:

If any Alt Key is pressed

bool isLeftAltPressed() const

Returns:

If the left Alt Key is pressed

bool isAltGrPressed() const

Returns:

If the right Alt Key is pressed

bool isMetaPressed() const

Returns:

If the Meta Key is pressed

bool isMouseLeftPressed() const

Returns:

If mouse left button it’s pressed

bool isMouseRightPressed() const

Returns:

If mouse right button it’s pressed

bool isMouseMiddlePressed() const

Returns:

If mouse middle button it’s pressed

bool mouseLeftClicked() const

Returns:

If mouse left click was clicked

bool mouseRightClicked() const

Returns:

If mouse right click was clicked

bool mouseMiddleClicked() const

Returns:

If mouse middle button (scroll button) was clicked.

bool mouseLeftDoubleClicked() const

Returns:

If mouse left click was double clicked

bool mouseRightDoubleClicked() const

Returns:

If mouse right click was double clicked

bool mouseMiddleDoubleClicked() const

Returns:

If mouse middle button (scroll button) was double clicked.

bool mouseWheelScrolledUp() const

Returns:

If mouse wheel up scrolled

bool mouseWheelScrolledDown() const

Returns:

If mouse wheel down scrolled

Uint32 pushCallback(const InputCallback& cb)

Push a new input callback.

Returns:

The Callback Id

void popCallback(const Uint32& CallbackId)

Pop the callback id indicated.

Vector2i getMousePos() const

Returns:

The Mouse position vector

void setMousePos(const Vector2i& Pos)

This will change the value of the mouse pos, will not REALLY move the mouse ( for that is InjectMousePos ).

Vector2f getMousePosFromView(const View& View)

Returns:

The mouse position over the current view

void setMouseSpeed(const Float& Speed)

Set the mouse speed ( only affects grabed windows )

const Float& getMouseSpeed() const

Returns:

The Mouse Speed

const Uint32& getLastPressTrigger() const

Returns:

The bitflags of the last pressed trigger (before the current state of press trigger)

const Uint32& getPressTrigger() const

Triggers are used mostly for the UI components. They are simple to manage. The mouse flags are defined in keycodes.hpp For Example The usage is simple, to know if the left mouse click is pressed you need to check against the left mouse flag mask if ( myInput->PressTrigger() & EE_BUTTON_LMASK ) …

Returns:

The current state as flags of the mouse press trigger

const Uint32& getReleaseTrigger() const

Returns:

The current state as flags of the mouse release trigger

const Uint32& getClickTrigger() const

Returns:

The current state as flags of the mouse click trigger

const Uint32& getDoubleClickTrigger() const

Returns:

The current state as flags of the mouse double click trigger

const Time& getDoubleClickInterval() const

Returns:

The double click interval in milliseconds ( default 500 ms )

void setDoubleClickInterval(const Time& Interval)

Set the double click interval in milliseconds

void cleanStates()

Clean the keyboard and mouse states

void sendEvent(InputEvent* Event)

Send an input event to the window

JoystickManager* getJoystickManager() const

Returns:

The joystick manager

Uint32 getFingerCount()

Returns:

The maximun number of fingers

InputFinger* getFingerIndex(const Uint32& Index)

Returns:

The input finger from it’s index

InputFinger* getFinger(const Int64& fingerId)

Returns:

The Input Finder from it’s id

std::vector<InputFinger*> getFingersDown()

Returns:

A list of the input finders that are currently down

std::vector<InputFinger*> getFingersWasDown()

Returns:

A list of the input finders that were down in the last update

const Uint32& getModState() const

Returns:

the state of the mod keys.

void processEvent(InputEvent* Event)

Process an input event. Called by the input update.

const Uint64& getEventsSentId() const

Returns:

An id of the current event update processed (