From fe229598d7437a85988eb9255cd0f6bdb6e07cb7 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 21 Feb 2010 19:45:50 +0000 Subject: optimized keyboard input handling routines --- src/client/key.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/client/key.h') diff --git a/src/client/key.h b/src/client/key.h index 3bb3e2b..3d97dd1 100644 --- a/src/client/key.h +++ b/src/client/key.h @@ -11,19 +11,24 @@ #include +#include "client/action.h" + namespace client { -/// a pressable key /** + * @brief a key on the keyboard * a Key instance can contain any kind of 'key' like a keyboard key, - * a mouse button, or a joystick button + * a mouse button, or a joystick button. Any key can be bound to + * a command string or an action. + * @see Action + * @see Keyboard */ class Key { public: /// define a new key - Key(const char *name, int keysym, char ascii = 0, const char *bind = 0); + Key(const char *name, int keysym, char ascii = 0); ~Key(); /// key modifiers @@ -33,7 +38,7 @@ public: void clear(); /// set the bind for a specific modifier - void assign(Modifier mod, const char *bind); + void assign(Modifier mod, const char *bind, Action *action = 0); /// clear the bind for a specific modifier void clear(Modifier mod); @@ -41,6 +46,11 @@ public: /// return the bind for a specific modifier std::string const & bind(Modifier mod) const; + /// return the action this key is bound to, 0 if unbound + inline Action *action() const { + return key_action; + } + /// first time the key was pressed since previous release inline float pressed() const { return key_pressed; @@ -74,8 +84,10 @@ public: private: std::string key_name; - int key_sym; + int key_sym; char key_ascii; + + Action *key_action; std::string key_bind; std::string key_bind_shift; -- cgit v1.2.3