HIDKeys.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003-2005 The Pentagram team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #include "pent_include.h"
00020 #include "HIDKeys.h"
00021 
00022 struct KeyName {HID_Key key; const char* name;};
00023 
00024 static const KeyName keyNames[] =
00025 {
00026         {HID_BACKSPACE, "Backspace"},
00027         {HID_TAB, "Tab"},
00028 
00029         {HID_ENTER, "Enter"},
00030         {HID_ENTER, "Return"},
00031 
00032         {HID_ESCAPE, "Escape"},
00033         {HID_SPACE, "Space"},
00034 
00035         {HID_EXCLAIM, "Exclaim"},
00036         {HID_SPACE, ""},
00037 
00038         {HID_DOUBLEQUOTE, "Double-Quote"},
00039         {HID_DOUBLEQUOTE, "\""},
00040 
00041         {HID_HASH, "Hash"},
00042         {HID_HASH, "#"},
00043 
00044         {HID_DOLLAR, "Dollar"},
00045         {HID_DOLLAR, "$"},
00046 
00047         {HID_PERCENT, "Percent"},
00048         {HID_PERCENT, "%"},
00049 
00050         {HID_AMPERSAND, "Ampersand"},
00051         {HID_AMPERSAND, "&"},
00052 
00053         {HID_QUOTE, "Quote"},
00054         {HID_QUOTE, "\'"},
00055 
00056         {HID_LEFTPAREN, "Left-Paren"},
00057         {HID_LEFTPAREN, "("},
00058         {HID_RIGHTPAREN, "Right-Paren"},
00059         {HID_RIGHTPAREN, ")"},
00060 
00061         {HID_ASTERISK, "Asterisk"},
00062         {HID_ASTERISK, "Star"},
00063         {HID_ASTERISK, "*"},
00064 
00065         {HID_PLUS, "Plus"},
00066         {HID_PLUS, "+"},
00067 
00068         {HID_COMMA, "Comma"},
00069         {HID_COMMA, ","},
00070 
00071         {HID_MINUS, "Minus"},
00072         {HID_MINUS, "-"},
00073 
00074         {HID_PERIOD, "Period"},
00075         {HID_PERIOD, "."},
00076 
00077         {HID_SLASH, "Slash"},
00078         {HID_SLASH, "/"},
00079 
00080         {HID_0, "0"},
00081         {HID_1, "1"},
00082         {HID_2, "2"},
00083         {HID_3, "3"},
00084         {HID_4, "4"},
00085         {HID_5, "5"},
00086         {HID_6, "6"},
00087         {HID_7, "7"},
00088         {HID_8, "8"},
00089         {HID_9, "9"},
00090 
00091         {HID_COLON, "Colon"},
00092         {HID_COLON, ":"},
00093 
00094         {HID_SEMICOLON, "Semicolon"},
00095         {HID_SEMICOLON, ";"},
00096 
00097         {HID_LEFTANGLE, "Left-Angle"},
00098         {HID_LEFTANGLE, "Less"},
00099         {HID_LEFTANGLE, "<"},
00100 
00101         {HID_EQUALS, "Equals"},
00102         {HID_EQUALS, "="},
00103 
00104         {HID_RIGHTANGLE, "Right-Angle"},
00105         {HID_RIGHTANGLE, "Greater"},
00106         {HID_RIGHTANGLE, ">"},
00107 
00108         {HID_QUESTION, "Question"},
00109         {HID_QUESTION, "?"},
00110 
00111         {HID_AT, "At"},
00112         {HID_AT, "@"},
00113 
00114         {HID_A, "A"},
00115         {HID_B, "B"},
00116         {HID_C, "C"},
00117         {HID_D, "D"},
00118         {HID_E, "E"},
00119         {HID_F, "F"},
00120         {HID_G, "G"},
00121         {HID_H, "H"},
00122         {HID_I, "I"},
00123         {HID_J, "J"},
00124         {HID_K, "K"},
00125         {HID_L, "L"},
00126         {HID_M, "M"},
00127         {HID_N, "N"},
00128         {HID_O, "O"},
00129         {HID_P, "P"},
00130         {HID_Q, "Q"},
00131         {HID_R, "R"},
00132         {HID_S, "S"},
00133         {HID_T, "T"},
00134         {HID_U, "U"},
00135         {HID_V, "V"},
00136         {HID_W, "W"},
00137         {HID_X, "X"},
00138         {HID_Y, "Y"},
00139         {HID_Z, "Z"},
00140 
00141         {HID_LEFTBRACKET, "Left-Bracket"},
00142         {HID_LEFTBRACKET, "["},
00143 
00144         {HID_BACKSLASH, "Backslash"},
00145         {HID_BACKSLASH, "\\"},
00146 
00147         {HID_RIGHTBRACKET, "Right-Bracket"},
00148         {HID_RIGHTBRACKET, "]"},
00149 
00150         {HID_CARET, "Caret"},
00151         {HID_CARET, "Hat"},
00152         {HID_CARET, "^"},
00153 
00154         {HID_UNDERSCORE, "Underscore"},
00155         {HID_UNDERSCORE, "_"},
00156 
00157         {HID_BACKQUOTE, "Backquote"},
00158         {HID_BACKQUOTE, "Grave"},
00159         {HID_BACKQUOTE, "`"},
00160 
00161         {HID_LEFTBRACE, "Left-Brace"},
00162         {HID_LEFTBRACE, "{"},
00163 
00164         {HID_VERTICALBAR, "Vertical-Bar"},
00165         {HID_VERTICALBAR, "Pipe"},
00166         {HID_VERTICALBAR, "Bar"},
00167         {HID_VERTICALBAR, "|"},
00168 
00169         {HID_RIGHTBRACE, "Right-Brace"},
00170         {HID_RIGHTBRACE, "}"},
00171 
00172         {HID_TILDE, "Tilde"},
00173         {HID_TILDE, "~"},
00174 
00175         {HID_KP0, "Keypad0"},
00176         {HID_KP1, "Keypad1"},
00177         {HID_KP2, "Keypad2"},
00178         {HID_KP3, "Keypad3"},
00179         {HID_KP4, "Keypad4"},
00180         {HID_KP5, "Keypad5"},
00181         {HID_KP6, "Keypad6"},
00182         {HID_KP7, "Keypad7"},
00183         {HID_KP8, "Keypad8"},
00184         {HID_KP9, "Keypad9"},
00185 
00186         {HID_KP_PERIOD, "Keypad-Period"},
00187         {HID_KP_SLASH, "Keypad-Slash"},
00188 
00189         {HID_KP_ASTERISK, "Keypad-Asterisk"},
00190         {HID_KP_ASTERISK, "Keypad-Star"},
00191 
00192         {HID_KP_MINUS, "Keypad-Minus"},
00193         {HID_KP_PLUS, "Keypad-Plus"},
00194         {HID_KP_ENTER, "Keypad-Enter"},
00195 
00196         {HID_UP, "Up"},
00197         {HID_DOWN, "Down"},
00198         {HID_LEFT, "Left"},
00199         {HID_RIGHT, "Right"},
00200         {HID_INSERT, "Insert"},
00201         {HID_DELETE, "Delete"},
00202         {HID_HOME, "Home"},
00203         {HID_END, "End"},
00204         {HID_PAGEUP, "Page-Up"},
00205         {HID_PAGEDOWN, "Page-Down"},
00206 
00207         {HID_F1, "F1"},
00208         {HID_F2, "F2"},
00209         {HID_F3, "F3"},
00210         {HID_F4, "F4"},
00211         {HID_F5, "F5"},
00212         {HID_F6, "F6"},
00213         {HID_F7, "F7"},
00214         {HID_F8, "F8"},
00215         {HID_F9, "F9"},
00216         {HID_F10, "F10"},
00217         {HID_F11, "F11"},
00218         {HID_F12, "F12"},
00219         {HID_F13, "F13"},
00220         {HID_F14, "F14"},
00221         {HID_F15, "F15"},
00222 
00223         {HID_PRINT, "Print"},
00224         {HID_NUM_LOCK, "Num-Lock"},
00225         {HID_CAPS_LOCK, "Caps-Lock"},
00226         {HID_SCROLL_LOCK, "Scroll-Lock"},
00227         {HID_PAUSE, "Pause"},
00228 
00229         {HID_LEFTSHIFT, "Left-Shift"},
00230         {HID_RIGHTSHIFT, "Right-Shift"},
00231 
00232         {HID_LEFTCONTROL, "Left-Control"},
00233         {HID_LEFTCONTROL, "Left-Ctrl"},
00234 
00235         {HID_RIGHTCONTROL, "Right-Control"},
00236         {HID_RIGHTCONTROL, "Right-Ctrl"},
00237 
00238         {HID_LEFTALT, "Left-Alt"},
00239         {HID_RIGHTALT, "Right-Alt"},
00240 
00241         {HID_MOUSE1, "Mouse1"},
00242         {HID_MOUSE2, "Mouse2"},
00243         {HID_MOUSE3, "Mouse3"},
00244         {HID_MOUSE4, "Mouse4"},
00245         {HID_MOUSE5, "Mouse5"},
00246         {HID_MOUSE6, "Mouse6"},
00247         {HID_MOUSE7, "Mouse7"},
00248         {HID_MOUSE8, "Mouse8"},
00249         {HID_MOUSE9, "Mouse9"},
00250         {HID_MOUSE10, "Mouse10"},
00251         {HID_MOUSE11, "Mouse11"},
00252         {HID_MOUSE12, "Mouse12"},
00253         {HID_MOUSE13, "Mouse13"},
00254         {HID_MOUSE14, "Mouse14"},
00255         {HID_MOUSE15, "Mouse15"},
00256         {HID_MOUSE16, "Mouse16"},
00257 
00258         {HID_JOY1, "Joy1"},
00259         {HID_JOY2, "Joy2"},
00260         {HID_JOY3, "Joy3"},
00261         {HID_JOY4, "Joy4"},
00262         {HID_JOY5, "Joy5"},
00263         {HID_JOY6, "Joy6"},
00264         {HID_JOY7, "Joy7"},
00265         {HID_JOY8, "Joy8"},
00266         {HID_JOY9, "Joy9"},
00267         {HID_JOY10, "Joy10"},
00268         {HID_JOY11, "Joy11"},
00269         {HID_JOY12, "Joy12"},
00270         {HID_JOY13, "Joy13"},
00271         {HID_JOY14, "Joy14"},
00272         {HID_JOY15, "Joy15"},
00273         {HID_JOY16, "Joy16"},
00274 
00275         {HID_LAST, ""}
00276 };
00277 
00278 struct EventName {HID_Event event; const char* name;};
00279 
00280 static const EventName eventNames[] =
00281 {
00282         {HID_EVENT_DEPRESS, "<Depress>"},
00283         {HID_EVENT_RELEASE, "<Release>"},
00284         {HID_EVENT_DOUBLE, "<Double>"},
00285         {HID_EVENT_CLICK, "<Click>"},
00286         {HID_EVENT_LAST, ""}
00287 };
00288 
00289 const char *HID_GetKeyName(HID_Key key)
00290 {
00291         int i;
00292         for (i=0; keyNames[i].key != HID_LAST; ++i)
00293         {
00294                 if (key == keyNames[i].key)
00295                         return keyNames[i].name;
00296         }
00297         return "";
00298 }
00299 
00300 HID_Key HID_GetKeyFromName(Pentagram::istring & name)
00301 {
00302         int i;
00303         for (i=0; keyNames[i].key != HID_LAST; ++i)
00304         {
00305                 if (name == keyNames[i].name)
00306                         return keyNames[i].key;
00307         }
00308         return HID_LAST;
00309 }
00310 
00311 HID_Key HID_translateSDLKey(SDLKey key)
00312 {
00313         switch(key)
00314         {
00315                 case SDLK_BACKSPACE: return HID_BACKSPACE;
00316                 case SDLK_TAB: return HID_TAB;
00317                 case SDLK_RETURN: return HID_ENTER;
00318                 case SDLK_SPACE: return HID_SPACE;
00319                 case SDLK_EXCLAIM: return HID_EXCLAIM;
00320                 case SDLK_QUOTEDBL: return HID_DOUBLEQUOTE;
00321                 case SDLK_HASH: return HID_HASH;
00322                 case SDLK_DOLLAR: return HID_DOLLAR;
00323 //              case : return HID_PERCENT;
00324                 case SDLK_AMPERSAND: return HID_AMPERSAND;
00325                 case SDLK_QUOTE: return HID_QUOTE;
00326                 case SDLK_LEFTPAREN: return HID_LEFTPAREN;
00327                 case SDLK_RIGHTPAREN: return HID_RIGHTPAREN;
00328                 case SDLK_ASTERISK: return HID_ASTERISK;
00329                 case SDLK_PLUS: return HID_PLUS;
00330                 case SDLK_COMMA: return HID_COMMA;
00331                 case SDLK_MINUS: return HID_MINUS;
00332                 case SDLK_PERIOD: return HID_PERIOD;
00333                 case SDLK_SLASH: return HID_SLASH;
00334                 case SDLK_0: return HID_0;
00335                 case SDLK_1: return HID_1;
00336                 case SDLK_2: return HID_2;
00337                 case SDLK_3: return HID_3;
00338                 case SDLK_4: return HID_4;
00339                 case SDLK_5: return HID_5;
00340                 case SDLK_6: return HID_6;
00341                 case SDLK_7: return HID_7;
00342                 case SDLK_8: return HID_8;
00343                 case SDLK_9: return HID_9;
00344                 case SDLK_COLON: return HID_COLON;
00345                 case SDLK_SEMICOLON: return HID_SEMICOLON;
00346                 case SDLK_LESS: return HID_LEFTANGLE;
00347                 case SDLK_EQUALS: return HID_EQUALS;
00348                 case SDLK_GREATER: return HID_RIGHTANGLE;
00349                 case SDLK_QUESTION: return HID_QUESTION;
00350                 case SDLK_AT: return HID_AT;
00351                 case SDLK_a: return HID_A;
00352                 case SDLK_b: return HID_B;
00353                 case SDLK_c: return HID_C;
00354                 case SDLK_d: return HID_D;
00355                 case SDLK_e: return HID_E;
00356                 case SDLK_f: return HID_F;
00357                 case SDLK_g: return HID_G;
00358                 case SDLK_h: return HID_H;
00359                 case SDLK_i: return HID_I;
00360                 case SDLK_j: return HID_J;
00361                 case SDLK_k: return HID_K;
00362                 case SDLK_l: return HID_L;
00363                 case SDLK_m: return HID_M;
00364                 case SDLK_n: return HID_N;
00365                 case SDLK_o: return HID_O;
00366                 case SDLK_p: return HID_P;
00367                 case SDLK_q: return HID_Q;
00368                 case SDLK_r: return HID_R;
00369                 case SDLK_s: return HID_S;
00370                 case SDLK_t: return HID_T;
00371                 case SDLK_u: return HID_U;
00372                 case SDLK_v: return HID_V;
00373                 case SDLK_w: return HID_W;
00374                 case SDLK_x: return HID_X;
00375                 case SDLK_y: return HID_Y;
00376                 case SDLK_z: return HID_Z;
00377                 case SDLK_LEFTBRACKET: return HID_LEFTBRACKET;
00378                 case SDLK_BACKSLASH: return HID_BACKSLASH;
00379                 case SDLK_RIGHTBRACKET: return HID_RIGHTBRACKET;
00380                 case SDLK_CARET: return HID_CARET;
00381                 case SDLK_UNDERSCORE: return HID_UNDERSCORE;
00382                 case SDLK_BACKQUOTE: return HID_BACKQUOTE;
00383 //              case : return HID_LEFTBRACE;
00384 //              case : return HID_VERTICALBAR;
00385 //              case : return HID_RIGHTBRACE;
00386 //              case : return HID_TILDE;
00387                 case SDLK_DELETE: return HID_DELETE;
00388                 case SDLK_INSERT: return HID_INSERT;
00389                 case SDLK_END: return HID_END;
00390                 case SDLK_HOME: return HID_HOME;
00391                 case SDLK_PAGEDOWN: return HID_PAGEDOWN;
00392                 case SDLK_PAGEUP: return HID_PAGEUP;
00393                 case SDLK_UP: return HID_UP;
00394                 case SDLK_DOWN: return HID_DOWN;
00395                 case SDLK_LEFT: return HID_LEFT;
00396                 case SDLK_RIGHT: return HID_RIGHT;
00397                 case SDLK_KP0: return HID_KP0;
00398                 case SDLK_KP1: return HID_KP1;
00399                 case SDLK_KP2: return HID_KP2;
00400                 case SDLK_KP3: return HID_KP3;
00401                 case SDLK_KP4: return HID_KP4;
00402                 case SDLK_KP5: return HID_KP5;
00403                 case SDLK_KP6: return HID_KP6;
00404                 case SDLK_KP7: return HID_KP7;
00405                 case SDLK_KP8: return HID_KP8;
00406                 case SDLK_KP9: return HID_KP9;
00407                 case SDLK_KP_PERIOD: return HID_KP_PERIOD;
00408                 case SDLK_KP_DIVIDE: return HID_KP_SLASH;
00409                 case SDLK_KP_MULTIPLY: return HID_KP_ASTERISK;
00410                 case SDLK_KP_MINUS: return HID_KP_MINUS;
00411                 case SDLK_KP_PLUS: return HID_KP_PLUS;
00412                 case SDLK_KP_ENTER: return HID_KP_ENTER;
00413                 case SDLK_KP_EQUALS: return HID_KP_EQUALS;
00414                 case SDLK_F1: return HID_F1;
00415                 case SDLK_F2: return HID_F2;
00416                 case SDLK_F3: return HID_F3;
00417                 case SDLK_F4: return HID_F4;
00418                 case SDLK_F5: return HID_F5;
00419                 case SDLK_F6: return HID_F6;
00420                 case SDLK_F7: return HID_F7;
00421                 case SDLK_F8: return HID_F8;
00422                 case SDLK_F9: return HID_F9;
00423                 case SDLK_F10: return HID_F10;
00424                 case SDLK_F11: return HID_F11;
00425                 case SDLK_F12: return HID_F12;
00426                 case SDLK_F13: return HID_F13;
00427                 case SDLK_F14: return HID_F14;
00428                 case SDLK_F15: return HID_F15;
00429                 case SDLK_PRINT: return HID_PRINT;
00430                 case SDLK_NUMLOCK: return HID_NUM_LOCK;
00431                 case SDLK_CAPSLOCK: return HID_CAPS_LOCK;
00432                 case SDLK_SCROLLOCK: return HID_SCROLL_LOCK;
00433                 case SDLK_PAUSE: return HID_PAUSE;
00434                 case SDLK_ESCAPE: return HID_ESCAPE;
00435                 case SDLK_RSHIFT: return HID_RIGHTSHIFT;
00436                 case SDLK_LSHIFT: return HID_LEFTSHIFT;
00437                 case SDLK_RCTRL: return HID_RIGHTCONTROL;
00438                 case SDLK_LCTRL: return HID_LEFTCONTROL;
00439                 case SDLK_RALT: return HID_RIGHTALT;
00440                 case SDLK_LALT: return HID_LEFTALT;
00441                 default:
00442                         break;
00443         }
00444         return HID_LAST;
00445 }
00446 
00447 HID_Key HID_translateSDLMouseButton(uint8 button)
00448 {
00449         switch(button)
00450         {
00451                 case 1: return HID_MOUSE1;
00452                 case 2: return HID_MOUSE2;
00453                 case 3: return HID_MOUSE3;
00454                 case 4: return HID_MOUSE4;
00455                 case 5: return HID_MOUSE5;
00456                 case 6: return HID_MOUSE6;
00457                 case 7: return HID_MOUSE7;
00458                 case 8: return HID_MOUSE8;
00459                 case 9: return HID_MOUSE9;
00460                 case 10: return HID_MOUSE10;
00461                 case 11: return HID_MOUSE11;
00462                 case 12: return HID_MOUSE12;
00463                 case 13: return HID_MOUSE13;
00464                 case 14: return HID_MOUSE14;
00465                 case 15: return HID_MOUSE15;
00466                 case 16: return HID_MOUSE16;
00467                 default:
00468                         break;
00469         }
00470         return HID_LAST;
00471 }
00472 
00473 HID_Key HID_translateSDLJoystickButton(uint8 button)
00474 {
00475         switch(button)
00476         {
00477                 case 1: return HID_JOY1;
00478                 case 2: return HID_JOY2;
00479                 case 3: return HID_JOY3;
00480                 case 4: return HID_JOY4;
00481                 case 5: return HID_JOY5;
00482                 case 6: return HID_JOY6;
00483                 case 7: return HID_JOY7;
00484                 case 8: return HID_JOY8;
00485                 case 9: return HID_JOY9;
00486                 case 10: return HID_JOY10;
00487                 case 11: return HID_JOY11;
00488                 case 12: return HID_JOY12;
00489                 case 13: return HID_JOY13;
00490                 case 14: return HID_JOY14;
00491                 case 15: return HID_JOY15;
00492                 case 16: return HID_JOY16;
00493                 default:
00494                         break;
00495         }
00496         return HID_LAST;
00497 }
00498 
00499 const char *HID_GetEventName(HID_Event event)
00500 {
00501         int i;
00502         for (i=0; eventNames[i].event != HID_EVENT_LAST; ++i)
00503         {
00504                 if (event == eventNames[i].event)
00505                         return eventNames[i].name;
00506         }
00507         return "";
00508 }
00509 
00510 HID_Event HID_GetEventFromName(Pentagram::istring & name)
00511 {
00512         int i;
00513         for (i=0; eventNames[i].event != HID_EVENT_LAST; ++i)
00514         {
00515                 if (name == eventNames[i].name)
00516                         return eventNames[i].event;
00517         }
00518         return HID_EVENT_LAST;
00519 }
00520 

Generated on Fri Jul 27 22:27:18 2007 for pentagram by  doxygen 1.4.7