2 fegdk: FE Game Development Kit
3 Copyright (C) 2001-2008 Alexey "waker" Yakovenko
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 waker@users.sourceforge.net
23 #ifndef __F_KEYBINDER_H
24 #define __F_KEYBINDER_H
26 #include "f_baseobject.h"
31 /** The keyBinderClass is used to bind key combinations to some user-specified actions.
32 * Only one action may be bound to one keycombo.
34 class FE_API keyBinder
: public baseObject
37 // the whole system may be a bit slow due to std::map lookup
38 // --> may be replaced with ushort array w/ 64k cost
40 // maps keycode to action
41 typedef std::map
<int, cStr
> handlersMap
;
42 handlersMap mHandlers
;
46 enum { lalt
= (1<<16), lctrl
= (1<<17), lshift
= (1<<18), ralt
= (1<<19), rctrl
= (1<<20), rshift
= (1<<21), alt
= (1<<22), shift
= (1<<23), ctrl
= (1<<24)};
49 virtual ~keyBinder (void);
51 /** Binds keycombo to a console command (string value).
52 * @param keycombo Same as for bindToUserAction
53 * @param cmd Pointer to a string, containint console command
55 void bind (int keycombo
, const char *cmd
);
57 /** Unbinds specified combo.
58 * @param keycombo Key combination
60 void unbind (int keycombo
);
62 /** Unbinds all keys, i.e. resets entire system.
64 void unbindAll (void);
67 * @return keycode for string value
69 int keycodeForString (const char *str
) const;
73 * @param keycode specifies keycombo to handle
74 * @return true if keycombo was accepted
76 bool keyDown (int keycombo
);
79 * Handles key release.
80 * @param keycombo specifies keycombo to handle
81 * @return true if keycombo was accepted
83 bool keyUp (int keycombo
);
89 #endif // __F_KEYBINDER_H