/* client/key.h This file is part of the Osirion project and is distributed under the terms and conditions of the GNU General Public License version 2 */ #ifndef __INCLUDED_CLIENT_KEY_H__ #define __INCLUDED_CLIENT_KEY_H__ #include "SDL/SDL.h" #include namespace client { /// a pressable key /** * a Key instance can contain any kind of 'key' like a keyboard key, * a mouse button, or a joystick button */ class Key { public: /// define a new key Key(const char *name, int keysym, char ascii = 0, const char *bind = 0); ~Key(); /// key modifiers enum Modifier { None = 0, Shift = KMOD_LSHIFT + KMOD_RSHIFT, Ctrl = KMOD_LCTRL + KMOD_RCTRL, Alt = KMOD_LALT + KMOD_RALT }; /// clear all binds void clear(); /// set the bind for a specific modifier void assign(Modifier mod, const char *bind); /// clear the bind for a specific modifier void clear(Modifier mod); /// return the bind for a specific modifier std::string const & bind(Modifier mod) const; /// first time the key was pressed since previous release inline float pressed() const { return key_pressed; } /// last time the key was pressed (includes repeats) inline float lastpressed() const { return key_lastpressed; } /// time the key was pressed when it is released inline float waspressed() const { return key_waspressed; } inline std::string const & name() const { return key_name; } inline char ascii() const { return key_ascii; } inline int sym() const { return key_sym; } float key_pressed; float key_lastpressed; float key_waspressed; private: std::string key_name; int key_sym; char key_ascii; std::string key_bind; std::string key_bind_shift; std::string key_bind_ctrl; std::string key_bind_alt; }; } // namespace client #endif // __INCLUDED_CLIENT_KEY_H__