From 8c17868585e2a12f947ec387947c4521ef21d775 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 2 Jun 2008 16:20:47 +0000 Subject: keyboard binds --- src/client/keyboard.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 5 deletions(-) (limited to 'src/client/keyboard.h') diff --git a/src/client/keyboard.h b/src/client/keyboard.h index 6805818..fb9efaf 100644 --- a/src/client/keyboard.h +++ b/src/client/keyboard.h @@ -4,21 +4,77 @@ the terms and conditions of the GNU General Public License version 2 */ -#ifndef __INCLUDED_CLIENT_KEYS_H__ -#define __INCLUDED_CLIENT_KEYS_H__ +#ifndef __INCLUDED_CLIENT_KEYBOARD_H__ +#define __INCLUDED_CLIENT_KEYBOARD_H__ + +#include +#include #include "SDL/SDL.h" +#include "client/key.h" + namespace client { +class Keyboard +{ +public: + Keyboard(); + ~Keyboard(); + + /// find a key on a keysym + Key *find(unsigned int keysym); + + /// find a key on name + Key *find(std::string const & name); + + /// bind a string to a key + void bind(std::string const &name, const std::string str); + + /// clear the string bound to a key + void unbind(std::string const &name); + + /// list keyboard key names + void list_keys(); + + /// list keyboard binds + void list_binds(); + + /// load keyboard binds + void load_binds(); + + /// save keyboard binds + void save_binds(); + + /// a key has been pressed + Key *press(unsigned int sym); + + /// a key has been pressed + Key *release(unsigned int sym); + +private: + typedef std::map::iterator iterator; + + inline iterator begin() { return keys.begin(); } + + inline iterator end() { return keys.end(); } + + void add_key(const char *name, const unsigned int keysym, const char ascii=0, const char *bind=0); + + std::map keys; + + bool numlock; + bool capslock; +}; + /// convert SDL_keysym to a keystroke -int translate_keysym(const SDL_keysym &keysym); +unsigned int translate_keysym(const SDL_keysym &keysym); /// set the keyboard input mode /** @param input true for console input, false for game input */ void setkeyboardmode(bool input); -} // namespace client +} -#endif // __INCLUDED_CLIENT_KEYS_H__ +#endif // __INCLUDED_CLIENT_KEYBOARD_H__ -- cgit v1.2.3