2014-02-14 15:50:00 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Created by [Dennis Andersen] [2013]
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef INPUT_KEBOARD_H
|
|
|
|
#define INPUT_KEBOARD_H
|
|
|
|
|
|
|
|
#include "InputObject.h"
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Input
|
|
|
|
{
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------------------
|
|
|
|
namespace Enum
|
|
|
|
{
|
|
|
|
//! Contains keycodes (Enum::SAKI -> Super Awsome Key Input)
|
|
|
|
enum SAKI
|
|
|
|
{
|
|
|
|
SAKI_Backspace ,
|
|
|
|
SAKI_Tab ,
|
|
|
|
SAKI_Enter ,
|
|
|
|
SAKI_LeftShift ,
|
|
|
|
SAKI_RightShift ,
|
|
|
|
SAKI_LeftAlt ,
|
|
|
|
SAKI_RightAlt ,
|
|
|
|
SAKI_LeftCtrl ,
|
|
|
|
SAKI_RightCtrl ,
|
|
|
|
SAKI_Pause ,
|
|
|
|
SAKI_CapsLock ,
|
|
|
|
SAKI_Escape ,
|
|
|
|
SAKI_Space ,
|
|
|
|
SAKI_PgUp ,
|
|
|
|
SAKI_PgDown ,
|
|
|
|
SAKI_End ,
|
|
|
|
SAKI_Home ,
|
|
|
|
SAKI_Left ,
|
|
|
|
SAKI_Up ,
|
|
|
|
SAKI_Right ,
|
|
|
|
SAKI_Down ,
|
|
|
|
SAKI_PrintScreen ,
|
|
|
|
SAKI_Insert ,
|
|
|
|
SAKI_Delete ,
|
|
|
|
SAKI_0 ,
|
|
|
|
SAKI_1 ,
|
|
|
|
SAKI_2 ,
|
|
|
|
SAKI_3 ,
|
|
|
|
SAKI_4 ,
|
|
|
|
SAKI_5 ,
|
|
|
|
SAKI_6 ,
|
|
|
|
SAKI_7 ,
|
|
|
|
SAKI_8 ,
|
|
|
|
SAKI_9 ,
|
2014-02-24 16:01:06 +01:00
|
|
|
SAK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
|
|
|
|
SAKI_F6 ,
|
|
|
|
SAKI_F7 ,
|
|
|
|
SAKI_F8 ,
|
|
|
|
SAKI_F9 ,
|
|
|
|
SAKI_F10 ,
|
|
|
|
SAKI_F11 ,
|
|
|
|
SAKI_F12 ,
|
|
|
|
SAKI_F13 ,
|
|
|
|
SAKI_F14 ,
|
|
|
|
SAKI_F15 ,
|
|
|
|
SAKI_F16 ,
|
|
|
|
SAKI_F17 ,
|
|
|
|
SAKI_F18 ,
|
|
|
|
SAKI_F19 ,
|
|
|
|
SAKI_F20 ,
|
|
|
|
SAKI_F21 ,
|
|
|
|
SAKI_F22 ,
|
|
|
|
SAKI_F23 ,
|
|
|
|
SAKI_F24 ,
|
|
|
|
SAKI_Numlock ,
|
|
|
|
SAKI_ScrlLock ,
|
|
|
|
SAKI_VolumeMute,
|
|
|
|
SAKI_VolumeDown,
|
|
|
|
SAKI_VolumeUp,
|
|
|
|
SAKI_MediaNext,
|
|
|
|
SAKI_MediaPrev,
|
|
|
|
SAKI_MediaStop,
|
|
|
|
SAKI_MediaPlayPause,
|
|
|
|
|
|
|
|
SAKI_Unknown
|
|
|
|
};
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------------------
|
2014-02-25 14:20:11 +01:00
|
|
|
namespace Struct
|
|
|
|
{
|
|
|
|
struct KeyboardEventData
|
|
|
|
{
|
|
|
|
Enum::SAKI key;
|
|
|
|
Enum::ButtonState state;
|
|
|
|
Keyboard* sender;
|
|
|
|
void* tag;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------------------
|
2014-02-14 15:50:00 +01:00
|
|
|
namespace Typedefs
|
|
|
|
{
|
2014-02-25 14:20:11 +01:00
|
|
|
typedef void(*OnKeyEventCallback) (const Struct::KeyboardEventData& eventData);
|
|
|
|
typedef void(*OnKeyPressCallback) (Enum::SAKI key, Keyboard* sender, void* tag);
|
|
|
|
typedef void(*OnKeyDownCallback) (Enum::SAKI key, Keyboard* sender, void* tag);
|
|
|
|
typedef void(*OnKeyReleaseCallback) (Enum::SAKI key, Keyboard* sender, void* tag);
|
2014-02-14 15:50:00 +01:00
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class Keyboard :public InputObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class KeyboardEvent
|
|
|
|
{
|
|
|
|
public:
|
2014-02-25 14:20:11 +01:00
|
|
|
virtual void OnKeyEvent (const Struct::KeyboardEventData& eventData) { }
|
|
|
|
virtual void OnKeyPress (Enum::SAKI key, Keyboard* sender) { }
|
|
|
|
virtual void OnKeyDown (Enum::SAKI key, Keyboard* sender) { }
|
|
|
|
virtual void OnKeyRelease (Enum::SAKI key, Keyboard* sender) { }
|
2014-02-14 15:50:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
public: /* Manual check functions */
|
2014-02-20 16:15:47 +01:00
|
|
|
virtual ~Keyboard();
|
|
|
|
|
2014-02-14 15:50:00 +01:00
|
|
|
virtual bool IsKeyUp (Enum::SAKI key) = 0;
|
|
|
|
virtual bool IsKeyDown (Enum::SAKI key) = 0;
|
2014-02-21 11:43:05 +01:00
|
|
|
virtual wchar_t* GetAsText(Enum::SAKI key) = 0;
|
2014-02-14 15:50:00 +01:00
|
|
|
|
2014-02-24 16:01:06 +01:00
|
|
|
public: /* From InputObject */
|
|
|
|
virtual void Activate () override = 0;
|
|
|
|
virtual void Deactivate () override = 0;
|
|
|
|
virtual bool IsActive() override = 0;
|
|
|
|
|
2014-02-25 14:20:11 +01:00
|
|
|
public: /* object subscribe functions */
|
|
|
|
void AddKeyboardEvent (KeyboardEvent* object);
|
|
|
|
void RemoveKeyboardEvent (KeyboardEvent* object);
|
|
|
|
void operator+= (KeyboardEvent* object);
|
|
|
|
void operator-= (KeyboardEvent* object);
|
2014-02-14 15:50:00 +01:00
|
|
|
|
2014-02-25 14:20:11 +01:00
|
|
|
public: /* global subscribe callback functions */
|
|
|
|
void AddOnKeyEventCallback (Typedefs::OnKeyEventCallback func, void* tag);
|
|
|
|
void AddOnKeyPressCallback (Typedefs::OnKeyPressCallback func, void* tag);
|
|
|
|
void AddOnKeyDownCallback (Typedefs::OnKeyDownCallback func, void* tag);
|
|
|
|
void AddOnKeyReleaseCallback (Typedefs::OnKeyReleaseCallback func, void* tag);
|
|
|
|
|
|
|
|
void RemoveOnKeyEventCallback (Typedefs::OnKeyEventCallback func);
|
|
|
|
void RemoveOnKeyPressCallback (Typedefs::OnKeyPressCallback func);
|
|
|
|
void RemoveOnKeyDownCallback (Typedefs::OnKeyDownCallback func);
|
2014-02-14 15:50:00 +01:00
|
|
|
void RemoveOnKeyReleaseCallback (Typedefs::OnKeyReleaseCallback func);
|
|
|
|
|
|
|
|
public:
|
2014-02-25 14:20:11 +01:00
|
|
|
|
2014-02-14 15:50:00 +01:00
|
|
|
|
2014-02-21 11:43:05 +01:00
|
|
|
void BindTextTarget( ::std::wstring *field );
|
|
|
|
void ReleaseTextTarget();
|
2014-02-14 15:50:00 +01:00
|
|
|
|
2014-02-21 11:43:05 +01:00
|
|
|
public:
|
|
|
|
struct KeyboardCallbackList;
|
2014-02-14 15:50:00 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
Keyboard();
|
|
|
|
|
2014-02-21 11:43:05 +01:00
|
|
|
protected: /* Internal event proc */
|
2014-02-25 14:20:11 +01:00
|
|
|
void InternalOnEvent(Struct::KeyboardEventData& data);
|
2014-02-24 16:01:06 +01:00
|
|
|
void InternalOnKeyPress(Enum::SAKI key);
|
|
|
|
void InternalOnKeyDown(Enum::SAKI key);
|
|
|
|
void InternalOnKeyRelease(Enum::SAKI key);
|
2014-02-14 15:50:00 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
std::vector<KeyboardEvent*> keyEventSubscrivers;
|
|
|
|
KeyboardCallbackList* callbackList;
|
2014-02-21 11:43:05 +01:00
|
|
|
::std::wstring* textTarget;
|
|
|
|
::std::wstring::size_type writePos;
|
|
|
|
bool active;
|
2014-02-14 15:50:00 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !INPUT_KEBOARD_H
|