00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(_XRB_KEY_HPP_)
00012 #define _XRB_KEY_HPP_
00013
00014 #include "xrb.hpp"
00015
00016 #include <string>
00017
00018 #include "xrb_eventhandler.hpp"
00019
00020 namespace Xrb
00021 {
00022
00028 class Key : public EventHandler
00029 {
00030 public:
00031
00036 enum Code
00037 {
00038 INVALID = -1,
00039 NONE = -2,
00040 UNKNOWN = 0,
00041 LEFTMOUSE,
00042 MIDDLEMOUSE,
00043 RIGHTMOUSE,
00044 MOUSEWHEELUP,
00045 MOUSEWHEELDOWN,
00046 BACKSPACE,
00047 TAB = '\t',
00048 CLEAR,
00049 RETURN = '\r',
00050 PAUSE,
00051 ESCAPE = '\x1B',
00052 SPACE = ' ',
00053 QUOTE = '\'',
00054 COMMA = ',',
00055 MINUS = '-',
00056 PERIOD = '.',
00057 SLASH = '/',
00058 ZERO = '0',
00059 ONE = '1',
00060 TWO = '2',
00061 THREE = '3',
00062 FOUR = '4',
00063 FIVE = '5',
00064 SIX = '6',
00065 SEVEN = '7',
00066 EIGHT = '8',
00067 NINE = '9',
00068 SEMICOLON = ';',
00069 EQUALS = '=',
00070 LEFTBRACKET = '[',
00071 BACKSLASH = '\\',
00072 RIGHTBRACKET = ']',
00073 BACKQUOTE = '`',
00074 A = 'a',
00075 B = 'b',
00076 C = 'c',
00077 D = 'd',
00078 E = 'e',
00079 F = 'f',
00080 G = 'g',
00081 H = 'h',
00082 I = 'i',
00083 J = 'j',
00084 K = 'k',
00085 L = 'l',
00086 M = 'm',
00087 N = 'n',
00088 O = 'o',
00089 P = 'p',
00090 Q = 'q',
00091 R = 'r',
00092 S = 's',
00093 T = 't',
00094 U = 'u',
00095 V = 'v',
00096 W = 'w',
00097 X = 'x',
00098 Y = 'y',
00099 Z = 'z',
00100 DELETE = '\x7F',
00101 WORLD_0,
00102 WORLD_1,
00103 WORLD_2,
00104 WORLD_3,
00105 WORLD_4,
00106 WORLD_5,
00107 WORLD_6,
00108 WORLD_7,
00109 WORLD_8,
00110 WORLD_9,
00111 WORLD_10,
00112 WORLD_11,
00113 WORLD_12,
00114 WORLD_13,
00115 WORLD_14,
00116 WORLD_15,
00117 WORLD_16,
00118 WORLD_17,
00119 WORLD_18,
00120 WORLD_19,
00121 WORLD_20,
00122 WORLD_21,
00123 WORLD_22,
00124 WORLD_23,
00125 WORLD_24,
00126 WORLD_25,
00127 WORLD_26,
00128 WORLD_27,
00129 WORLD_28,
00130 WORLD_29,
00131 WORLD_30,
00132 WORLD_31,
00133 WORLD_32,
00134 WORLD_33,
00135 WORLD_34,
00136 WORLD_35,
00137 WORLD_36,
00138 WORLD_37,
00139 WORLD_38,
00140 WORLD_39,
00141 WORLD_40,
00142 WORLD_41,
00143 WORLD_42,
00144 WORLD_43,
00145 WORLD_44,
00146 WORLD_45,
00147 WORLD_46,
00148 WORLD_47,
00149 WORLD_48,
00150 WORLD_49,
00151 WORLD_50,
00152 WORLD_51,
00153 WORLD_52,
00154 WORLD_53,
00155 WORLD_54,
00156 WORLD_55,
00157 WORLD_56,
00158 WORLD_57,
00159 WORLD_58,
00160 WORLD_59,
00161 WORLD_60,
00162 WORLD_61,
00163 WORLD_62,
00164 WORLD_63,
00165 WORLD_64,
00166 WORLD_65,
00167 WORLD_66,
00168 WORLD_67,
00169 WORLD_68,
00170 WORLD_69,
00171 WORLD_70,
00172 WORLD_71,
00173 WORLD_72,
00174 WORLD_73,
00175 WORLD_74,
00176 WORLD_75,
00177 WORLD_76,
00178 WORLD_77,
00179 WORLD_78,
00180 WORLD_79,
00181 WORLD_80,
00182 WORLD_81,
00183 WORLD_82,
00184 WORLD_83,
00185 WORLD_84,
00186 WORLD_85,
00187 WORLD_86,
00188 WORLD_87,
00189 WORLD_88,
00190 WORLD_89,
00191 WORLD_90,
00192 WORLD_91,
00193 WORLD_92,
00194 WORLD_93,
00195 WORLD_94,
00196 WORLD_95,
00197 KP0,
00198 KP1,
00199 KP2,
00200 KP3,
00201 KP4,
00202 KP5,
00203 KP6,
00204 KP7,
00205 KP8,
00206 KP9,
00207 KP_PERIOD,
00208 KP_DIVIDE,
00209 KP_MULTIPLY,
00210 KP_MINUS,
00211 KP_PLUS,
00212 KP_ENTER,
00213 KP_EQUALS,
00214 UP,
00215 DOWN,
00216 RIGHT,
00217 LEFT,
00218 INSERT,
00219 HOME,
00220 END,
00221 PAGEUP,
00222 PAGEDOWN,
00223 F1,
00224 F2,
00225 F3,
00226 F4,
00227 F5,
00228 F6,
00229 F7,
00230 F8,
00231 F9,
00232 F10,
00233 F11,
00234 F12,
00235 F13,
00236 F14,
00237 F15,
00238 NUMLOCK,
00239 CAPSLOCK,
00240 SCROLLLOCK,
00241 RSHIFT,
00242 LSHIFT,
00243 RCTRL,
00244 LCTRL,
00245 RALT,
00246 LALT,
00247 RMETA,
00248 LMETA,
00249 LWINBLOWS,
00250 RWINBLOWS,
00251 MODE,
00252 COMPOSE,
00253 HELP,
00254 PRINT,
00255 SYSREQ,
00256 BREAK,
00257 MENU,
00258 POWER,
00259 EURO,
00260 UNDO
00261 };
00262
00267 enum Modifier
00268 {
00269 MOD_NONE = 0x0000,
00270 MOD_LSHIFT = 0x0001,
00271 MOD_RSHIFT = 0x0002,
00272 MOD_LCTRL = 0x0040,
00273 MOD_RCTRL = 0x0080,
00274 MOD_LALT = 0x0100,
00275 MOD_RALT = 0x0200,
00276 MOD_LMETA = 0x0400,
00277 MOD_RMETA = 0x0800,
00278 MOD_NUM = 0x1000,
00279 MOD_CAPS = 0x2000,
00280 MOD_MODE = 0x4000,
00281
00282
00283 MOD_SHIFT = MOD_LSHIFT|MOD_RSHIFT,
00284 MOD_ALT = MOD_LALT|MOD_RALT,
00285 MOD_CTRL = MOD_LCTRL|MOD_RCTRL
00286 };
00287
00288 ~Key () { }
00289
00290 static Key *Create (Key::Code key, std::string const &name);
00291
00292 static bool IsKeyRepeatable (Key::Code code);
00293 static bool IsKeyAscii (Key::Code code);
00294 inline Key::Code GetCode () const { return m_code; }
00295 inline std::string const &Name () const { return m_name; }
00296 inline bool IsPressed () const { return m_is_pressed; }
00297
00298
00299 void ResetPressed ();
00300
00301 protected:
00302
00303
00304 Key ();
00305
00306
00307 virtual bool HandleEvent (Event const *e);
00308
00309 private:
00310
00311
00312 Key::Code m_code;
00313
00314 std::string m_name;
00315
00316 bool m_is_pressed;
00317 };
00318
00319 }
00320
00321 #endif // !defined(_XRB_KEY_HPP_)