00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include "cxutils/keyboard.h"
00042 #include <iostream>
00043
00044 #ifdef WIN32
00045 #define _WIN32_WINNT 0x0501
00046 #include <windows.h>
00047 #include <conio.h>
00048 #else
00049 #include <X11/extensions/XTest.h>
00050 #include <X11/keysym.h>
00051 #include <X11/Xlib.h>
00052 #include <X11/cursorfont.h>
00053 #include <X11/Xutil.h>
00054 #include <unistd.h>
00055 #include <sys/time.h>
00056 #include <termios.h>
00057 #include <assert.h>
00058 #endif
00059
00060 using namespace CxUtils;
00061
00067 int CxUtils::GetChar()
00068 {
00069 int ch = 0;
00070 #ifdef WIN32
00071 if(_kbhit())
00072 {
00073 ch = _getch();
00074 }
00075 #else
00076 struct termios initial_settings;
00077 struct termios new_settings;
00078 int nread;
00079
00080
00081 tcgetattr(0, &initial_settings);
00082 new_settings = initial_settings;
00083 new_settings.c_lflag &= ~ICANON;
00084 new_settings.c_lflag &= ~ECHO;
00085 new_settings.c_lflag &= ~ISIG;
00086 new_settings.c_cc[VMIN] = 1;
00087 new_settings.c_cc[VTIME] = 0;
00088
00089 tcsetattr(0, TCSANOW, &new_settings);
00090
00091
00092 new_settings.c_cc[VMIN] = 0;
00093 tcsetattr(0, TCSANOW, &new_settings);
00094 nread = read(0, &ch, 1);
00095 new_settings.c_cc[VMIN] = 1;
00096 tcsetattr(0, TCSANOW, &new_settings);
00097
00098 if(nread != 1)
00099 {
00100 ch = 0;
00101 }
00102
00103
00104 tcsetattr(0, TCSANOW, &initial_settings);
00105
00106
00107 #endif
00108
00109 return ch;
00110 }
00111
00112
00113 #ifndef WIN32
00114
00115 unsigned int GetBit(char* keyboard, unsigned int index)
00116 {
00117 return keyboard[index/8] & (1 << (index%8));
00118 }
00119
00120 #endif
00121
00122
00128 Keyboard::Keyboard()
00129 {
00130 mTimer.RegisterTimerEvent(Keyboard::KeyboardTimerEvent, this);
00131 }
00132
00133
00139 Keyboard::~Keyboard()
00140 {
00141 mTimer.Stop();
00142 mKeyStates.clear();
00143 }
00144
00145
00156 bool Keyboard::RegisterCallback(CxUtils::Keyboard::Callback *cb)
00157 {
00158 mCallbacksMutex.Lock();
00159 mCallbacks.insert(cb);
00160 mCallbacksMutex.Unlock();
00161
00162 if(mTimer.IsActive() == false)
00163 {
00164 for(unsigned int i = 0; i < MaxKeys; i++)
00165 {
00166 mKeyStates[(Key)i] = IsKeyDown((Key)i);
00167 }
00168 mTimer.Start(25);
00169 }
00170 return mTimer.IsActive();
00171 }
00172
00173
00181 void Keyboard::RemoveCallback(CxUtils::Keyboard::Callback *cb)
00182 {
00183 mCallbacksMutex.Lock();
00184 if(mCallbacks.find(cb) != mCallbacks.end())
00185 {
00186 mCallbacks.erase(mCallbacks.find(cb));
00187 }
00188 if(mCallbacks.size() == 0)
00189 {
00190 mTimer.Stop();
00191 }
00192 mCallbacksMutex.Unlock();
00193 }
00194
00195
00201 void Keyboard::KeyboardTimerEvent(void *args)
00202 {
00203 std::vector<Key> downKeys;
00204 std::vector<Key> upKeys;
00205 std::vector<Key>::iterator keyEvent;
00206
00207 std::map<Key, bool>::iterator k;
00208 Keyboard::Callback::Set::iterator cb;
00209
00210 Keyboard* keyboard = (Keyboard*)args;
00211
00212 for(k = keyboard->mKeyStates.begin(); k != keyboard->mKeyStates.end(); k++)
00213 {
00214 bool down = IsKeyDown(k->first);
00215 if(down && k->second == false)
00216 {
00217 downKeys.push_back(k->first);
00218 }
00219 else if(down == false && k->second == true)
00220 {
00221 upKeys.push_back(k->first);
00222 }
00223 k->second = down;
00224 }
00225
00226 keyboard->mCallbacksMutex.Lock();
00227 for(keyEvent = downKeys.begin();
00228 keyEvent != downKeys.end();
00229 keyEvent++)
00230 {
00231 for(cb = keyboard->mCallbacks.begin();
00232 cb != keyboard->mCallbacks.end();
00233 cb++)
00234 {
00235 (*cb)->ProcessKeyEvent(*keyEvent, true);
00236 }
00237 }
00238
00239 for(keyEvent = upKeys.begin();
00240 keyEvent != upKeys.end();
00241 keyEvent++)
00242 {
00243 for(cb = keyboard->mCallbacks.begin();
00244 cb != keyboard->mCallbacks.end();
00245 cb++)
00246 {
00247 (*cb)->ProcessKeyEvent(*keyEvent, false);
00248 }
00249 }
00250
00251 keyboard->mCallbacksMutex.Unlock();
00252 }
00253
00266 bool Keyboard::IsKeyDown(const Key key)
00267 {
00268 bool result = false;
00269 #ifdef WIN32
00270 SHORT _key = 0;
00271 if(key == Any)
00272 {
00273 for(int k = 1; k < MaxKeys; k++)
00274 {
00275 if(IsKeyDown((Key)k))
00276 {
00277 result = true;
00278 break;
00279 }
00280 }
00281 }
00282 else
00283 {
00284 _key = ::GetAsyncKeyState((int)LookupHostSystemKey(key));
00285 if( (_key & 0x8000) != 0 )
00286 {
00287 result = true;
00288 }
00289 }
00290 #else
00291 Display* display = XOpenDisplay(NULL);
00292 char keyboard[32];
00293
00294 XSynchronize(display, true);
00295 if(XQueryKeymap(display, keyboard))
00296 {
00297 if(key == Any)
00298 {
00299 for(unsigned int i = 0; i < 32; i++)
00300 {
00301 char c = keyboard[i];
00302 for(unsigned int b = 0; b < 8; b++)
00303 {
00304 if( (c & 0x1) )
00305 {
00306 result = true;
00307 break;
00308 }
00309 c = c >> 1;
00310 }
00311 }
00312 }
00313 else
00314 {
00315 KeySym keySym = LookupHostSystemKey(key);
00316 KeyCode keyCode = XKeysymToKeycode(display, keySym);
00317 if(IsModifierKey( keySym ) )
00318 {
00319 XModifierKeymap* map = XGetModifierMapping(display);
00320 int iKeyMask = 0;
00321 unsigned int iMask = 0;
00322 Window wDummy1, wDummy2;
00323 int iDummy3, iDummy4, iDummy5, iDummy6;
00324
00325 for(int i = 0; i < 8; ++i)
00326 {
00327 if(map->modifiermap[map->max_keypermod*i] == keyCode)
00328 {
00329 iKeyMask = 1 << i;
00330 }
00331 }
00332 XQueryPointer(display, DefaultRootWindow(display), &wDummy1, &wDummy2,
00333 &iDummy3, &iDummy4, &iDummy5, &iDummy6, &iMask);
00334 XFreeModifiermap(map);
00335 result = (iMask & iKeyMask) != 0;
00336 }
00337 else
00338 {
00339 if( (keyboard[keyCode >> 3] & (1 << (keyCode & 7))) > 0)
00340 {
00341 result = true;
00342 }
00343 }
00344 }
00345 }
00346
00347 XCloseDisplay(display);
00348 #endif
00349 return result;
00350 }
00351
00352
00360 Keyboard::Key Keyboard::GetCurrentKey()
00361 {
00362 Key pressed = (Key)Invalid;
00363
00364 #ifdef WIN32
00365 for( int k = 1; k < MaxKeys; k++)
00366 {
00367 if(IsKeyDown( (Key)k ) )
00368 {
00369 pressed = (Key)k;
00370 break;
00371 }
00372 }
00373 #else
00374 Display* display = XOpenDisplay(NULL);
00375 char keyboard[32];
00376
00377 XSynchronize(display, true);
00378 bool done = false;
00379 if(XQueryKeymap(display, keyboard))
00380 {
00381 for(unsigned int i = 0; i < 32 && !done; i++)
00382 {
00383 char c = keyboard[i];
00384 for(unsigned int b = 0; b < 8; b++)
00385 {
00386 if( (c & 0x1) )
00387 {
00388 KeySym keySym = XKeycodeToKeysym(display, 8*i + b, true);
00389 pressed = LookupFromHostSystemKey(keySym);
00390 if(pressed == Invalid)
00391 {
00392 keySym = XKeycodeToKeysym(display, 8*i + b, false);
00393 pressed = LookupFromHostSystemKey(keySym);
00394 }
00395 done = true;
00396 break;
00397 }
00398 c = c >> 1;
00399 }
00400 }
00401 }
00402 XCloseDisplay(display);
00403 #endif
00404
00405 return pressed;
00406 }
00407
00408
00414 Keyboard::KeyList Keyboard::GetPressedKeys()
00415 {
00416 KeyList pressed;
00417 for(unsigned int k = 1; k < MaxKeys; k++)
00418 {
00419 if(IsKeyDown( (Key)k ) )
00420 {
00421 pressed.push_back( (Key)k );
00422 }
00423 }
00424 return pressed;
00425 }
00426
00427
00443 bool Keyboard::FakeKeyPress(const Keyboard::Key key,
00444 const bool releaseFlag,
00445 const bool directX)
00446 {
00447 bool result = false;
00448 if(key != Invalid && key != Any)
00449 {
00450 #ifdef WIN32
00451 ::INPUT k;
00452 k.type = INPUT_KEYBOARD;
00453 if(directX == false)
00454 {
00455 k.ki.wVk = (int)LookupHostSystemKey(key);
00456 k.ki.dwFlags = KEYEVENTF_UNICODE;
00457 k.ki.time = 0;
00458 k.ki.wScan = 0;
00459 k.ki.dwExtraInfo = 0;
00460 }
00461 else
00462 {
00463 k.ki.wVk = 0;
00464 k.ki.dwFlags = KEYEVENTF_SCANCODE;
00465 k.ki.time = 0;
00466 k.ki.wScan = LookupScanCodeDX(key);
00467 k.ki.dwExtraInfo = 0;
00468 }
00469
00470 if(::SendInput(1, &k, sizeof(::INPUT)) > 0)
00471 {
00472 result = true;
00473 if(releaseFlag)
00474 {
00475 FakeKeyRelease(key, directX);
00476 }
00477 }
00478 #else
00479 Display* display = XOpenDisplay(NULL);
00480 if(display)
00481 {
00482 if(XTestFakeKeyEvent(display, XKeysymToKeycode( display, LookupHostSystemKey(key)), true, 0) != 0)
00483 {
00484 result = true;
00485 if(releaseFlag)
00486 {
00487 XTestFakeKeyEvent(display, XKeysymToKeycode( display, LookupHostSystemKey(key)), false, 0);
00488 }
00489 }
00490 XCloseDisplay(display);
00491 }
00492 #endif
00493 }
00494
00495
00496 return result;
00497 }
00498
00499
00513 bool Keyboard::FakeKeyRelease(const Keyboard::Key key, const bool directX)
00514 {
00515 bool result = false;
00516 if(key != Invalid && key != Any)
00517 {
00518 #ifdef WIN32
00519 ::INPUT k;
00520 k.type = INPUT_KEYBOARD;
00521 if(directX == false)
00522 {
00523 k.ki.wVk = (int)LookupHostSystemKey(key);
00524 k.ki.dwFlags = KEYEVENTF_KEYUP | KEYEVENTF_UNICODE;
00525 k.ki.time = 0;
00526 k.ki.wScan = 0;
00527 k.ki.dwExtraInfo = 0;
00528 }
00529 else
00530 {
00531 k.ki.wVk = 0;
00532 k.ki.dwFlags = KEYEVENTF_KEYUP | KEYEVENTF_SCANCODE;
00533 k.ki.time = 0;
00534 k.ki.wScan = LookupScanCodeDX(key);
00535 k.ki.dwExtraInfo = 0;
00536 }
00537 if(::SendInput(1, &k, sizeof(::INPUT)) > 0)
00538 {
00539 result = true;
00540 }
00541 #else
00542 Display* display = XOpenDisplay(NULL);
00543 if(display)
00544 {
00545 if(XTestFakeKeyEvent(display, XKeysymToKeycode( display, LookupHostSystemKey(key)), false, 0) != 0)
00546 {
00547 result = true;
00548 }
00549 XCloseDisplay(display);
00550 }
00551 #endif
00552 }
00553 return result;
00554 }
00555
00556
00567 unsigned int Keyboard::LookupHostSystemKey(const Key key)
00568 {
00569 unsigned int value = 0;
00570 #ifdef WIN32
00571 switch(key)
00572 {
00573 case Backspace:
00574 value = VK_BACK;
00575 break;
00576 case Tab:
00577 value = VK_TAB;
00578 break;
00579 case Clear:
00580 value = VK_CLEAR;
00581 break;
00582 case Return:
00583 value = VK_RETURN;
00584 break;
00585 case ShiftLock:
00586 value = VK_CAPITAL;
00587 break;
00588 case Pause:
00589 value = VK_PAUSE;
00590 break;
00591 case CapsLock:
00592 value = VK_CAPITAL;
00593 break;
00594 case Escape:
00595 value = VK_ESCAPE;
00596 break;
00597 case Space:
00598 value = VK_SPACE;
00599 break;
00600 case PageUp:
00601 value = VK_PRIOR;
00602 break;
00603 case PageDown:
00604 value = VK_NEXT;
00605 break;
00606 case End:
00607 value = VK_END;
00608 break;
00609 case Home:
00610 value = VK_HOME;
00611 break;
00612 case LeftArrow:
00613 value = VK_LEFT;
00614 break;
00615 case UpArrow:
00616 value = VK_UP;
00617 break;
00618 case RightArrow:
00619 value = VK_RIGHT;
00620 break;
00621 case DownArrow:
00622 value = VK_DOWN;
00623 break;
00624 case Select:
00625 value = VK_SELECT;
00626 break;
00627 case Print:
00628 value = VK_SNAPSHOT;
00629 break;
00630 case Execute:
00631 value = VK_EXECUTE;
00632 break;
00633 case PrintScreen:
00634 value = VK_SNAPSHOT;
00635 break;
00636 case Insert:
00637 value = VK_INSERT;
00638 break;
00639 case Delete:
00640 value = VK_DELETE;
00641 break;
00642 case Help:
00643 value = VK_HELP;
00644 break;
00645 case Zero:
00646 value = 0x30;
00647 break;
00648 case One:
00649 value = 0x31;
00650 break;
00651 case Two:
00652 value = 0x32;
00653 break;
00654 case Three:
00655 value = 0x33;
00656 break;
00657 case Four:
00658 value = 0x34;
00659 break;
00660 case Five:
00661 value = 0x35;
00662 break;
00663 case Six:
00664 value = 0x36;
00665 break;
00666 case Seven:
00667 value = 0x37;
00668 break;
00669 case Eight:
00670 value = 0x38;
00671 break;
00672 case Nine:
00673 value = 0x39;
00674 break;
00675 case A:
00676 value = 0x41;
00677 break;
00678 case B:
00679 value = 0x42;
00680 break;
00681 case C:
00682 value = 0x43;
00683 break;
00684 case D:
00685 value = 0x44;
00686 break;
00687 case E:
00688 value = 0x45;
00689 break;
00690 case F:
00691 value = 0x46;
00692 break;
00693 case G:
00694 value = 0x47;
00695 break;
00696 case H:
00697 value = 0x48;
00698 break;
00699 case I:
00700 value = 0x49;
00701 break;
00702 case J:
00703 value = 0x4A;
00704 break;
00705 case K:
00706 value = 0x4B;
00707 break;
00708 case L:
00709 value = 0x4C;
00710 break;
00711 case M:
00712 value = 0x4D;
00713 break;
00714 case N:
00715 value = 0x4E;
00716 break;
00717 case O:
00718 value = 0x4F;
00719 break;
00720 case P:
00721 value = 0x50;
00722 break;
00723 case Q:
00724 value = 0x51;
00725 break;
00726 case R:
00727 value = 0x52;
00728 break;
00729 case S:
00730 value = 0x53;
00731 break;
00732 case T:
00733 value = 0x54;
00734 break;
00735 case U:
00736 value = 0x55;
00737 break;
00738 case V:
00739 value = 0x56;
00740 break;
00741 case W:
00742 value = 0x11;
00743 break;
00744 case X:
00745 value = 0x58;
00746 break;
00747 case Y:
00748 value = 0x59;
00749 break;
00750 case Z:
00751 value = 0x5A;
00752 break;
00753 case Numpad0:
00754 value = VK_NUMPAD0;
00755 break;
00756 case Numpad1:
00757 value = VK_NUMPAD1;
00758 break;
00759 case Numpad2:
00760 value = VK_NUMPAD2;
00761 break;
00762 case Numpad3:
00763 value = VK_NUMPAD3;
00764 break;
00765 case Numpad4:
00766 value = VK_NUMPAD4;
00767 break;
00768 case Numpad5:
00769 value = VK_NUMPAD5;
00770 break;
00771 case Numpad6:
00772 value = VK_NUMPAD6;
00773 break;
00774 case Numpad7:
00775 value = VK_NUMPAD7;
00776 break;
00777 case Numpad8:
00778 value = VK_NUMPAD8;
00779 break;
00780 case Numpad9:
00781 value = VK_NUMPAD9;
00782 break;
00783 case Multiply:
00784 value = VK_MULTIPLY;
00785 break;
00786 case Add:
00787 value = VK_ADD;
00788 break;
00789 case Separator:
00790 value = VK_SEPARATOR;
00791 break;
00792 case Subtract:
00793 value = VK_SUBTRACT;
00794 break;
00795 case Decimal:
00796 value = VK_DECIMAL;
00797 break;
00798 case Divide:
00799 value = VK_DIVIDE;
00800 break;
00801 case F1:
00802 value = VK_F1;
00803 break;
00804 case F2:
00805 value = VK_F2;
00806 break;
00807 case F3:
00808 value = VK_F3;
00809 break;
00810 case F4:
00811 value = VK_F4;
00812 break;
00813 case F5:
00814 value = VK_F5;
00815 break;
00816 case F6:
00817 value = VK_F6;
00818 break;
00819 case F7:
00820 value = VK_F7;
00821 break;
00822 case F8:
00823 value = VK_F8;
00824 break;
00825 case F9:
00826 value = VK_F9;
00827 break;
00828 case F10:
00829 value = VK_F10;
00830 break;
00831 case F11:
00832 value = VK_F11;
00833 break;
00834 case F12:
00835 value = VK_F12;
00836 break;
00837 case NumLock:
00838 value = VK_NUMLOCK;
00839 break;
00840 case ScrollLock:
00841 value = VK_SCROLL;
00842 break;
00843 case LeftShift:
00844 value = VK_LSHIFT;
00845 break;
00846 case RightShift:
00847 value = VK_RSHIFT;
00848 break;
00849 case LeftControl:
00850 value = VK_LCONTROL;
00851 break;
00852 case RightControl:
00853 value = VK_RCONTROL;
00854 break;
00855 case Comma:
00856 value = VK_OEM_COMMA;
00857 break;
00858 case Period:
00859 value = VK_OEM_PERIOD;
00860 break;
00861 case LeftAlt:
00862 value = VK_MENU;
00863 break;
00864 case RightAlt:
00865 value = VK_MENU;
00866 break;
00867 default:
00868 value = 0;
00869 break;
00870 }
00871 #else
00872 switch(key)
00873 {
00874 case Backspace:
00875 value = XK_BackSpace;
00876 break;
00877 case Tab:
00878 value = XK_Tab;
00879 break;
00880 case Clear:
00881 value = XK_Clear;
00882 break;
00883 case Return:
00884 value = XK_Return;
00885 break;
00886 case ShiftLock:
00887 value = XK_Shift_Lock;
00888 break;
00889 case Pause:
00890 value = XK_Pause;
00891 break;
00892 case CapsLock:
00893 value = XK_Caps_Lock;
00894 break;
00895 case Escape:
00896 value = XK_Escape;
00897 break;
00898 case Space:
00899 value = ' ';
00900 break;
00901 case PageUp:
00902 value = XK_Page_Up;
00903 break;
00904 case PageDown:
00905 value = XK_Page_Down;
00906 break;
00907 case End:
00908 value = XK_End;
00909 break;
00910 case Home:
00911 value = XK_Home;
00912 break;
00913 case LeftArrow:
00914 value = XK_Left;
00915 break;
00916 case UpArrow:
00917 value = XK_Up;
00918 break;
00919 case RightArrow:
00920 value = XK_Right;
00921 break;
00922 case DownArrow:
00923 value = XK_Down;
00924 break;
00925 case Select:
00926 value = XK_Select;
00927 break;
00928 case Print:
00929 value = XK_Print;
00930 break;
00931 case Execute:
00932 value = XK_Execute;
00933 break;
00934 case PrintScreen:
00935 value = XK_Print;
00936 break;
00937 case Insert:
00938 value = XK_Insert;
00939 break;
00940 case Delete:
00941 value = XK_Delete;
00942 break;
00943 case Help:
00944 value = XK_Help;
00945 break;
00946 case Zero:
00947 value = XK_0;
00948 break;
00949 case One:
00950 value = XK_1;
00951 break;
00952 case Two:
00953 value = XK_2;
00954 break;
00955 case Three:
00956 value = XK_3;
00957 break;
00958 case Four:
00959 value = XK_4;
00960 break;
00961 case Five:
00962 value = XK_5;
00963 break;
00964 case Six:
00965 value = XK_6;
00966 break;
00967 case Seven:
00968 value = XK_7;
00969 break;
00970 case Eight:
00971 value = XK_8;
00972 break;
00973 case Nine:
00974 value = XK_9;
00975 break;
00976 case A:
00977 value = XK_A;
00978 break;
00979 case B:
00980 value = XK_B;
00981 break;
00982 case C:
00983 value = XK_C;
00984 break;
00985 case D:
00986 value = XK_D;
00987 break;
00988 case E:
00989 value = XK_E;
00990 break;
00991 case F:
00992 value = XK_F;
00993 break;
00994 case G:
00995 value = XK_G;
00996 break;
00997 case H:
00998 value = XK_H;
00999 break;
01000 case I:
01001 value = XK_I;
01002 break;
01003 case J:
01004 value = XK_J;
01005 break;
01006 case K:
01007 value = XK_K;
01008 break;
01009 case L:
01010 value = XK_L;
01011 break;
01012 case M:
01013 value = XK_M;
01014 break;
01015 case N:
01016 value = XK_N;
01017 break;
01018 case O:
01019 value = XK_O;
01020 break;
01021 case P:
01022 value = XK_P;
01023 break;
01024 case Q:
01025 value = XK_Q;
01026 break;
01027 case R:
01028 value = XK_R;
01029 break;
01030 case S:
01031 value = XK_S;
01032 break;
01033 case T:
01034 value = XK_T;
01035 break;
01036 case U:
01037 value = XK_U;
01038 break;
01039 case V:
01040 value = XK_V;
01041 break;
01042 case W:
01043 value = XK_W;
01044 break;
01045 case X:
01046 value = XK_X;
01047 break;
01048 case Y:
01049 value = XK_Y;
01050 break;
01051 case Z:
01052 value = XK_Z;
01053 break;
01054 case Numpad0:
01055 value = XK_KP_0;
01056 break;
01057 case Numpad1:
01058 value = XK_KP_1;
01059 break;
01060 case Numpad2:
01061 value = XK_KP_2;
01062 break;
01063 case Numpad3:
01064 value = XK_KP_3;
01065 break;
01066 case Numpad4:
01067 value = XK_KP_4;
01068 break;
01069 case Numpad5:
01070 value = XK_KP_5;
01071 break;
01072 case Numpad6:
01073 value = XK_KP_6;
01074 break;
01075 case Numpad7:
01076 value = XK_KP_7;
01077 break;
01078 case Numpad8:
01079 value = XK_KP_8;
01080 break;
01081 case Numpad9:
01082 value = XK_KP_9;
01083 break;
01084 case Multiply:
01085 value = XK_KP_Multiply;
01086 break;
01087 case Add:
01088 value = XK_KP_Add;
01089 break;
01090 case Separator:
01091 value = XK_KP_Separator;
01092 break;
01093 case Subtract:
01094 value = XK_KP_Subtract;
01095 break;
01096 case Decimal:
01097 value = XK_KP_Decimal;
01098 break;
01099 case Divide:
01100 value = XK_KP_Divide;
01101 break;
01102 case F1:
01103 value = XK_F1;
01104 break;
01105 case F2:
01106 value = XK_F2;
01107 break;
01108 case F3:
01109 value = XK_F3;
01110 break;
01111 case F4:
01112 value = XK_F4;
01113 break;
01114 case F5:
01115 value = XK_F5;
01116 break;
01117 case F6:
01118 value = XK_F6;
01119 break;
01120 case F7:
01121 value = XK_F7;
01122 break;
01123 case F8:
01124 value = XK_F8;
01125 break;
01126 case F9:
01127 value = XK_F9;
01128 break;
01129 case F10:
01130 value = XK_F10;
01131 break;
01132 case F11:
01133 value = XK_F11;
01134 break;
01135 case F12:
01136 value = XK_F12;
01137 break;
01138 case NumLock:
01139 value = XK_Num_Lock;
01140 break;
01141 case ScrollLock:
01142 value = XK_Scroll_Lock;
01143 break;
01144 case LeftShift:
01145 value = XK_Shift_L;
01146 break;
01147 case RightShift:
01148 value = XK_Shift_R;
01149 break;
01150 case LeftControl:
01151 value = XK_Control_L;
01152 break;
01153 case RightControl:
01154 value = XK_Control_R;
01155 break;
01156 case Comma:
01157 value = XK_comma;
01158 break;
01159 case Period:
01160 value = XK_period;
01161 break;
01162 case LeftAlt:
01163 value = XK_Alt_L;
01164 break;
01165 case RightAlt:
01166 value = XK_Alt_R;
01167 break;
01168 default:
01169 value = 0;
01170 break;
01171 }
01172 #endif
01173 return value;
01174 }
01175
01176
01187 Keyboard::Key Keyboard::LookupFromHostSystemKey(const unsigned int hostKey)
01188 {
01189 Keyboard::Key value;
01190
01191 #ifdef WIN32
01192 if(hostKey >= 0x30 && hostKey <= 0x39)
01193 {
01194 return (Keyboard::Key)hostKey;
01195 }
01196 else if(hostKey >= 0x41 && hostKey <= 0x5A)
01197 {
01198 return (Keyboard::Key)hostKey;
01199 }
01200 switch(hostKey)
01201 {
01202 case VK_BACK:
01203 value = Backspace;
01204 break;
01205 case VK_TAB:
01206 value = Tab;
01207 break;
01208 case VK_CLEAR:
01209 value = Clear;
01210 break;
01211 case VK_RETURN:
01212 value = Return;
01213 break;
01214 case VK_CAPITAL:
01215 value = ShiftLock;
01216 break;
01217 case VK_PAUSE:
01218 value = Pause;
01219 break;
01220 case VK_ESCAPE:
01221 value = Escape;
01222 break;
01223 case VK_SPACE:
01224 value = Space;
01225 break;
01226 case VK_PRIOR:
01227 value = PageUp;
01228 break;
01229 case VK_NEXT:
01230 value = PageDown;
01231 break;
01232 case VK_END:
01233 value = End;
01234 break;
01235 case VK_HOME:
01236 value = Home;
01237 break;
01238 case VK_LEFT:
01239 value = LeftArrow;
01240 break;
01241 case VK_UP:
01242 value = UpArrow;
01243 break;
01244 case VK_RIGHT:
01245 value = RightArrow;
01246 break;
01247 case VK_DOWN:
01248 value = DownArrow;
01249 break;
01250 case VK_SELECT:
01251 value = Select;
01252 break;
01253 case VK_SNAPSHOT:
01254 value = Print;
01255 break;
01256 case VK_EXECUTE:
01257 value = Execute;
01258 break;
01259 case VK_INSERT:
01260 value = Insert;
01261 break;
01262 case VK_DELETE:
01263 value = Delete;
01264 break;
01265 case VK_HELP:
01266 value = Help;
01267 break;
01268 case VK_NUMPAD0:
01269 value = Numpad0;
01270 break;
01271 case VK_NUMPAD1:
01272 value = Numpad1;
01273 break;
01274 case VK_NUMPAD2:
01275 value = Numpad2;
01276 break;
01277 case VK_NUMPAD3:
01278 value = Numpad3;
01279 break;
01280 case VK_NUMPAD4:
01281 value = Numpad4;
01282 break;
01283 case VK_NUMPAD5:
01284 value = Numpad5;
01285 break;
01286 case VK_NUMPAD6:
01287 value = Numpad6;
01288 break;
01289 case VK_NUMPAD7:
01290 value = Numpad7;
01291 break;
01292 case VK_NUMPAD8:
01293 value = Numpad8;
01294 break;
01295 case VK_NUMPAD9:
01296 value = Numpad9;
01297 break;
01298 case VK_MULTIPLY:
01299 value = Multiply;
01300 break;
01301 case VK_ADD:
01302 value = Add;
01303 break;
01304 case VK_SEPARATOR:
01305 value = Separator;
01306 break;
01307 case VK_SUBTRACT:
01308 value = Subtract;
01309 break;
01310 case VK_DECIMAL:
01311 value = Decimal;
01312 break;
01313 case VK_DIVIDE:
01314 value = Divide;
01315 break;
01316 case VK_F1:
01317 value = F1;
01318 break;
01319 case VK_F2:
01320 value = F2;
01321 break;
01322 case VK_F3:
01323 value = F3;
01324 break;
01325 case VK_F4:
01326 value = F4;
01327 break;
01328 case VK_F5:
01329 value = F5;
01330 break;
01331 case VK_F6:
01332 value = F6;
01333 break;
01334 case VK_F7:
01335 value = F7;
01336 break;
01337 case VK_F8:
01338 value = F8;
01339 break;
01340 case VK_F9:
01341 value = F9;
01342 break;
01343 case VK_F10:
01344 value = F10;
01345 break;
01346 case VK_F11:
01347 value = F11;
01348 break;
01349 case VK_F12:
01350 value = F12;
01351 break;
01352 case VK_NUMLOCK:
01353 value = NumLock;
01354 break;
01355 case VK_SCROLL:
01356 value = ScrollLock;
01357 break;
01358 case VK_LSHIFT:
01359 value = LeftShift;
01360 break;
01361 case VK_RSHIFT:
01362 value = RightShift;
01363 break;
01364 case VK_LCONTROL:
01365 value = LeftControl;
01366 break;
01367 case VK_RCONTROL:
01368 value = RightControl;
01369 break;
01370 case VK_OEM_COMMA:
01371 value = Comma;
01372 break;
01373 case VK_OEM_PERIOD:
01374 value = Period;
01375 break;
01376 case VK_MENU:
01377 value = LeftAlt;
01378 break;
01379 default:
01380 value = Invalid;
01381 break;
01382 }
01383 #else
01384 switch(hostKey)
01385 {
01386 case XK_BackSpace:
01387 value = Backspace;
01388 break;
01389 case XK_Tab:
01390 value = Tab;
01391 break;
01392 case XK_Clear:
01393 value = Clear;
01394 break;
01395 case XK_Return:
01396 value = Return;
01397 break;
01398 case XK_Shift_Lock:
01399 value = ShiftLock;
01400 break;
01401 case XK_Pause:
01402 value = Pause;
01403 break;
01404 case XK_Caps_Lock:
01405 value = CapsLock;
01406 break;
01407 case XK_Escape:
01408 value = Escape;
01409 break;
01410 case XK_KP_Space:
01411 value = Space;
01412 break;
01413 case ' ':
01414 value = Space;
01415 break;
01416 case XK_Page_Up:
01417 value = PageUp;
01418 break;
01419 case XK_Page_Down:
01420 value = PageDown;
01421 break;
01422 case XK_End:
01423 value = End;
01424 break;
01425 case XK_Home:
01426 value = Home;
01427 break;
01428 case XK_Left:
01429 value = LeftArrow;
01430 break;
01431 case XK_Up:
01432 value = UpArrow;
01433 break;
01434 case XK_Right:
01435 value = RightArrow;
01436 break;
01437 case XK_Down:
01438 value = DownArrow;
01439 break;
01440 case XK_Select:
01441 value = Select;
01442 break;
01443 case XK_Execute:
01444 value = Execute;
01445 break;
01446 case XK_Print:
01447 value = PrintScreen;
01448 break;
01449 case XK_Insert:
01450 value = Insert;
01451 break;
01452 case XK_Delete:
01453 value = Delete;
01454 break;
01455 case XK_Help:
01456 value = Help;
01457 break;
01458 case XK_0:
01459 value = Zero;
01460 break;
01461 case XK_1:
01462 value = One;
01463 break;
01464 case XK_2:
01465 value = Two;
01466 break;
01467 case XK_3:
01468 value = Three;
01469 break;
01470 case XK_4:
01471 value = Four;
01472 break;
01473 case XK_5:
01474 value = Five;
01475 break;
01476 case XK_6:
01477 value = Six;
01478 break;
01479 case XK_7:
01480 value = Seven;
01481 break;
01482 case XK_8:
01483 value = Eight;
01484 break;
01485 case XK_9:
01486 value = Nine;
01487 break;
01488 case XK_A:
01489 value = A;
01490 break;
01491 case XK_B:
01492 value = B;
01493 break;
01494 case XK_C:
01495 value = C;
01496 break;
01497 case XK_D:
01498 value = D;
01499 break;
01500 case XK_E:
01501 value = E;
01502 break;
01503 case XK_F:
01504 value = F;
01505 break;
01506 case XK_G:
01507 value = G;
01508 break;
01509 case XK_H:
01510 value = H;
01511 break;
01512 case XK_I:
01513 value = I;
01514 break;
01515 case XK_J:
01516 value = J;
01517 break;
01518 case XK_K:
01519 value = K;
01520 break;
01521 case XK_L:
01522 value = L;
01523 break;
01524 case XK_M:
01525 value = M;
01526 break;
01527 case XK_N:
01528 value = N;
01529 break;
01530 case XK_O:
01531 value = O;
01532 break;
01533 case XK_P:
01534 value = P;
01535 break;
01536 case XK_Q:
01537 value = Q;
01538 break;
01539 case XK_R:
01540 value = R;
01541 break;
01542 case XK_S:
01543 value = S;
01544 break;
01545 case XK_T:
01546 value = T;
01547 break;
01548 case XK_U:
01549 value = U;
01550 break;
01551 case XK_V:
01552 value = V;
01553 break;
01554 case XK_W:
01555 value = W;
01556 break;
01557 case XK_X:
01558 value = X;
01559 break;
01560 case XK_Y:
01561 value = Y;
01562 break;
01563 case XK_Z:
01564 value = Z;
01565 break;
01566 case XK_KP_0:
01567 value = Numpad0;
01568 break;
01569 case XK_KP_1:
01570 value = Numpad1;
01571 break;
01572 case XK_KP_2:
01573 value = Numpad2;
01574 break;
01575 case XK_KP_3:
01576 value = Numpad3;
01577 break;
01578 case XK_KP_4:
01579 value = Numpad4;
01580 break;
01581 case XK_KP_5:
01582 value = Numpad5;
01583 break;
01584 case XK_KP_6:
01585 value = Numpad6;
01586 break;
01587 case XK_KP_7:
01588 value = Numpad7;
01589 break;
01590 case XK_KP_8:
01591 value = Numpad8;
01592 break;
01593 case XK_KP_9:
01594 value = Numpad9;
01595 break;
01596 case XK_KP_Multiply:
01597 value = Multiply;
01598 break;
01599 case XK_KP_Add:
01600 value = Add;
01601 break;
01602 case XK_KP_Separator:
01603 value = Separator;
01604 break;
01605 case XK_KP_Subtract:
01606 value = Subtract;
01607 break;
01608 case XK_KP_Decimal:
01609 value = Decimal;
01610 break;
01611 case XK_KP_Divide:
01612 value = Divide;
01613 break;
01614 case XK_F1:
01615 value = F1;
01616 break;
01617 case XK_F2:
01618 value = F2;
01619 break;
01620 case XK_F3:
01621 value = F3;
01622 break;
01623 case XK_F4:
01624 value = F4;
01625 break;
01626 case XK_F5:
01627 value = F5;
01628 break;
01629 case XK_F6:
01630 value = F6;
01631 break;
01632 case XK_F7:
01633 value = F7;
01634 break;
01635 case XK_F8:
01636 value = F8;
01637 break;
01638 case XK_F9:
01639 value = F9;
01640 break;
01641 case XK_F10:
01642 value = F10;
01643 break;
01644 case XK_F11:
01645 value = F11;
01646 break;
01647 case XK_F12:
01648 value = F12;
01649 break;
01650 case XK_Num_Lock:
01651 value = NumLock;
01652 break;
01653 case XK_Scroll_Lock:
01654 value = ScrollLock;
01655 break;
01656 case XK_Shift_L:
01657 value = LeftShift;
01658 break;
01659 case XK_Shift_R:
01660 value = RightShift;
01661 break;
01662 case XK_Control_L:
01663 value = LeftControl;
01664 break;
01665 case XK_Control_R:
01666 value = RightControl;
01667 break;
01668 case XK_comma:
01669 value = Comma;
01670 break;
01671 case XK_period:
01672 value = Period;
01673 break;
01674 case XK_Alt_L:
01675 value = LeftAlt;
01676 break;
01677 case XK_Alt_R:
01678 value = RightAlt;
01679 break;
01680 default:
01681 value = Invalid;
01682 break;
01683 }
01684 #endif
01685
01686 return value;
01687 }
01688
01689
01699 std::string Keyboard::ToString(const Key key)
01700 {
01701 std::string value;
01702
01703 switch(key)
01704 {
01705 case Backspace:
01706 value = "Backspace";
01707 break;
01708 case Tab:
01709 value = "Tab";
01710 break;
01711 case Clear:
01712 value = "Clear";
01713 break;
01714 case Return:
01715 value = "Return";
01716 break;
01717 case ShiftLock:
01718 value = "Shift Lock";
01719 break;
01720 case Pause:
01721 value = "Pause";
01722 break;
01723 case CapsLock:
01724 value = "Caps Lock";
01725 break;
01726 case Escape:
01727 value = "Escape";
01728 break;
01729 case Space:
01730 value = "Space Bar";
01731 break;
01732 case PageUp:
01733 value = "Page Up";
01734 break;
01735 case PageDown:
01736 value = "Page Down";
01737 break;
01738 case End:
01739 value = "End";
01740 break;
01741 case Home:
01742 value = "Home";
01743 break;
01744 case LeftArrow:
01745 value = "Left Arrow";
01746 break;
01747 case UpArrow:
01748 value = "Up Arrow";
01749 break;
01750 case RightArrow:
01751 value = "Right Arrow";
01752 break;
01753 case DownArrow:
01754 value = "Down Arrow";
01755 break;
01756 case Select:
01757 value = "Select";
01758 break;
01759 case Print:
01760 value = "Print";
01761 break;
01762 case Execute:
01763 value = "Execute";
01764 break;
01765 case PrintScreen:
01766 value = "Print Screen";
01767 break;
01768 case Insert:
01769 value = "Insert";
01770 break;
01771 case Delete:
01772 value = "Delete";
01773 break;
01774 case Help:
01775 value = "Help";
01776 break;
01777 case Zero:
01778 value = "0";
01779 break;
01780 case One:
01781 value = "1";
01782 break;
01783 case Two:
01784 value = "2";
01785 break;
01786 case Three:
01787 value = "3";
01788 break;
01789 case Four:
01790 value = "4";
01791 break;
01792 case Five:
01793 value = "5";
01794 break;
01795 case Six:
01796 value = "6";
01797 break;
01798 case Seven:
01799 value = "7";
01800 break;
01801 case Eight:
01802 value = "8";
01803 break;
01804 case Nine:
01805 value = "9";
01806 break;
01807 case A:
01808 value = "A";
01809 break;
01810 case B:
01811 value = "B";
01812 break;
01813 case C:
01814 value = "C";
01815 break;
01816 case D:
01817 value = "D";
01818 break;
01819 case E:
01820 value = "E";
01821 break;
01822 case F:
01823 value = "F";
01824 break;
01825 case G:
01826 value = "G";
01827 break;
01828 case H:
01829 value = "H";
01830 break;
01831 case I:
01832 value = "I";
01833 break;
01834 case J:
01835 value = "J";
01836 break;
01837 case K:
01838 value = "K";
01839 break;
01840 case L:
01841 value = "L";
01842 break;
01843 case M:
01844 value = "M";
01845 break;
01846 case N:
01847 value = "N";
01848 break;
01849 case O:
01850 value = "O";
01851 break;
01852 case P:
01853 value = "P";
01854 break;
01855 case Q:
01856 value = "Q";
01857 break;
01858 case R:
01859 value = "R";
01860 break;
01861 case S:
01862 value = "S";
01863 break;
01864 case T:
01865 value = "T";
01866 break;
01867 case U:
01868 value = "U";
01869 break;
01870 case V:
01871 value = "V";
01872 break;
01873 case W:
01874 value = "W";
01875 break;
01876 case X:
01877 value = "X";
01878 break;
01879 case Y:
01880 value = "Y";
01881 break;
01882 case Z:
01883 value = "Z";
01884 break;
01885 case Numpad0:
01886 value = "Numpad 0";
01887 break;
01888 case Numpad1:
01889 value = "Numpad 1";
01890 break;
01891 case Numpad2:
01892 value = "Numpad 2";
01893 break;
01894 case Numpad3:
01895 value = "Numpad 3";
01896 break;
01897 case Numpad4:
01898 value = "Numpad 4";
01899 break;
01900 case Numpad5:
01901 value = "Numpad 5";
01902 break;
01903 case Numpad6:
01904 value = "Numpad 6";
01905 break;
01906 case Numpad7:
01907 value = "Numpad 7";
01908 break;
01909 case Numpad8:
01910 value = "Numpad 8";
01911 break;
01912 case Numpad9:
01913 value = "Numpad 9";
01914 break;
01915 case Multiply:
01916 value = "Multiply";
01917 break;
01918 case Add:
01919 value = "Add";
01920 break;
01921 case Separator:
01922 value = "Separator";
01923 break;
01924 case Subtract:
01925 value = "Subtract";
01926 break;
01927 case Decimal:
01928 value = "Decimal";
01929 break;
01930 case Divide:
01931 value = "Divide";
01932 break;
01933 case F1:
01934 value = "F1";
01935 break;
01936 case F2:
01937 value = "F2";
01938 break;
01939 case F3:
01940 value = "F3";
01941 break;
01942 case F4:
01943 value = "F4";
01944 break;
01945 case F5:
01946 value = "F5";
01947 break;
01948 case F6:
01949 value = "F6";
01950 break;
01951 case F7:
01952 value = "F7";
01953 break;
01954 case F8:
01955 value = "F8";
01956 break;
01957 case F9:
01958 value = "F9";
01959 break;
01960 case F10:
01961 value = "F10";
01962 break;
01963 case F11:
01964 value = "F11";
01965 break;
01966 case F12:
01967 value = "F12";
01968 break;
01969 case NumLock:
01970 value = "Num Lock";
01971 break;
01972 case ScrollLock:
01973 value = "Scroll Lock";
01974 break;
01975 case LeftShift:
01976 value = "Left Shift";
01977 break;
01978 case RightShift:
01979 value = "Right Shift";
01980 break;
01981 case LeftControl:
01982 value = "Left Control";
01983 break;
01984 case RightControl:
01985 value = "Right Control";
01986 break;
01987 case Comma:
01988 value = "Comma";
01989 break;
01990 case Period:
01991 value = "Period";
01992 break;
01993 case LeftAlt:
01994 value = "Left Alt";
01995 break;
01996 case RightAlt:
01997 value = "Right Alt";
01998 break;
01999 default:
02000 value = "Unknown";
02001 break;
02002 }
02003 return value;
02004 }
02005
02006
02016 Keyboard::Key Keyboard::FromString(const std::string& strKey)
02017 {
02018 Key value;
02019
02020 if(strKey == "Backspace")
02021 {
02022 value = Backspace;
02023 }
02024 else if(strKey == "Tab")
02025 {
02026 value = Tab;
02027 }
02028 else if(strKey == "Clear")
02029 {
02030 value = Clear;
02031 }
02032 else if(strKey == "Return")
02033 {
02034 value = Return;
02035 }
02036 else if(strKey == "Shift Lock")
02037 {
02038 value = ShiftLock;
02039 }
02040 else if(strKey == "Pause")
02041 {
02042 value = Pause;
02043 }
02044 else if(strKey == "Caps Lock")
02045 {
02046 value = CapsLock;
02047 }
02048 else if(strKey == "Escape")
02049 {
02050 value = Escape;
02051 }
02052 else if(strKey == "Space Bar")
02053 {
02054 value = Space;
02055 }
02056 else if(strKey == "Page Up")
02057 {
02058 value = PageUp;
02059 }
02060 else if(strKey == "Page Down")
02061 {
02062 value = PageDown;
02063 }
02064 else if(strKey == "End")
02065 {
02066 value = End;
02067 }
02068 else if(strKey == "Home")
02069 {
02070 value = Home;
02071 }
02072 else if(strKey == "Left Arrow")
02073 {
02074 value = LeftArrow;
02075 }
02076 else if(strKey == "Up Arrow")
02077 {
02078 value = UpArrow;
02079 }
02080 else if(strKey == "Right Arrow")
02081 {
02082 value = RightArrow;
02083 }
02084 else if(strKey == "Down Arrow")
02085 {
02086 value = DownArrow;
02087 }
02088 else if(strKey == "Select")
02089 {
02090 value = Select;
02091 }
02092 else if(strKey == "Print")
02093 {
02094 value = Print;
02095 }
02096 else if(strKey == "Execute")
02097 {
02098 value = Execute;
02099 }
02100 else if(strKey == "Print")
02101 {
02102 value = Print;
02103 }
02104 else if(strKey == "Print Screen")
02105 {
02106 value = PrintScreen;
02107 }
02108 else if(strKey == "Insert")
02109 {
02110 value = Insert;
02111 }
02112 else if(strKey == "Delete")
02113 {
02114 value = Delete;
02115 }
02116 else if(strKey == "Help")
02117 {
02118 value = Help;
02119 }
02120 else if(strKey == "0")
02121 {
02122 value = Zero;
02123 }
02124 else if(strKey == "1")
02125 {
02126 value = One;
02127 }
02128 else if(strKey == "2")
02129 {
02130 value = Two;
02131 }
02132 else if(strKey == "3")
02133 {
02134 value = Three;
02135 }
02136 else if(strKey == "4")
02137 {
02138 value = Four;
02139 }
02140 else if(strKey == "5")
02141 {
02142 value = Five;
02143 }
02144 else if(strKey == "6")
02145 {
02146 value = Six;
02147 }
02148 else if(strKey == "7")
02149 {
02150 value = Seven;
02151 }
02152 else if(strKey == "8") {
02153 value = Eight;
02154 }
02155 else if(strKey == "9")
02156 {
02157 value = Nine;
02158 }
02159 else if(strKey == "A")
02160 {
02161 value = A;
02162 }
02163 else if(strKey == "B")
02164 {
02165 value = B;
02166 }
02167 else if(strKey == "C")
02168 {
02169 value = C;
02170 }
02171 else if(strKey == "D")
02172 {
02173 value = D;
02174 }
02175 else if(strKey == "E")
02176 {
02177 value = E;
02178 }
02179 else if(strKey == "F")
02180 {
02181 value = F;
02182 }
02183 else if(strKey == "G")
02184 {
02185 value = G;
02186 }
02187 else if(strKey == "H")
02188 {
02189 value = H;
02190 }
02191 else if(strKey == "I")
02192 {
02193 value = I;
02194 }
02195 else if(strKey == "J")
02196 {
02197 value = J;
02198 }
02199 else if(strKey == "K")
02200 {
02201 value = K;
02202 }
02203 else if(strKey == "L")
02204 {
02205 value = L;
02206 }
02207 else if(strKey == "M")
02208 {
02209 value = M;
02210 }
02211 else if(strKey == "N")
02212 {
02213 value = N;
02214 }
02215 else if(strKey == "O")
02216 {
02217 value = O;
02218 }
02219 else if(strKey == "P")
02220 {
02221 value = P;
02222 }
02223 else if(strKey == "Q")
02224 {
02225 value = Q;
02226 }
02227 else if(strKey == "R")
02228 {
02229 value = R;
02230 }
02231 else if(strKey == "S")
02232 {
02233 value = S;
02234 }
02235 else if(strKey == "T")
02236 {
02237 value = T;
02238 }
02239 else if(strKey == "U")
02240 {
02241 value = U;
02242 }
02243 else if(strKey == "V")
02244 {
02245 value = V;
02246 }
02247 else if(strKey == "W")
02248 {
02249 value = W;
02250 }
02251 else if(strKey == "X")
02252 {
02253 value = X;
02254 }
02255 else if(strKey == "Y")
02256 {
02257 value = Y;
02258 }
02259 else if(strKey == "Z")
02260 {
02261 value = Z;
02262 }
02263 else if(strKey == "Numpad 0")
02264 {
02265 value = Numpad0;
02266 }
02267 else if(strKey == "Numpad 1")
02268 {
02269 value = Numpad1;
02270 }
02271 else if(strKey == "Numpad 2")
02272 {
02273 value = Numpad2;
02274 }
02275 else if(strKey == "Numpad 3")
02276 {
02277 value = Numpad3;
02278 }
02279 else if(strKey == "Numpad 4")
02280 {
02281 value = Numpad4;
02282 }
02283 else if(strKey == "Numpad 5")
02284 {
02285 value = Numpad5;
02286 }
02287 else if(strKey == "Numpad 6")
02288 {
02289 value = Numpad6;
02290 }
02291 else if(strKey == "Numpad 7")
02292 {
02293 value = Numpad7;
02294 }
02295 else if(strKey == "Numpad 8")
02296 {
02297 value = Numpad8;
02298 }
02299 else if(strKey == "Numpad 9")
02300 {
02301 value = Numpad9;
02302 }
02303 else if(strKey == "Multiply")
02304 {
02305 value = Multiply;
02306 }
02307 else if(strKey == "Add")
02308 {
02309 value = Add;
02310 }
02311 else if(strKey == "Separator")
02312 {
02313 value = Separator;
02314 }
02315 else if(strKey == "Subtract")
02316 {
02317 value = Subtract;
02318 }
02319 else if(strKey == "Decimal")
02320 {
02321 value = Decimal;
02322 }
02323 else if(strKey == "Divide")
02324 {
02325 value = Divide;
02326 }
02327 else if(strKey == "F1")
02328 {
02329 value = F1;
02330 }
02331 else if(strKey == "F2")
02332 {
02333 value = F2;
02334 }
02335 else if(strKey == "F3")
02336 {
02337 value = F3;
02338 }
02339 else if(strKey == "F4")
02340 {
02341 value = F4;
02342 }
02343 else if(strKey == "F5")
02344 {
02345 value = F5;
02346 }
02347 else if(strKey == "F6")
02348 {
02349 value = F6;
02350 }
02351 else if(strKey == "F7")
02352 {
02353 value = F7;
02354 }
02355 else if(strKey == "F8")
02356 {
02357 value = F8;
02358 }
02359 else if(strKey == "F9")
02360 {
02361 value = F9;
02362 }
02363 else if(strKey == "F10")
02364 {
02365 value = F10;
02366 }
02367 else if(strKey == "F11")
02368 {
02369 value = F11;
02370 }
02371 else if(strKey == "F12")
02372 {
02373 value = F12;
02374 }
02375 else if(strKey == "Num Lock")
02376 {
02377 value = NumLock;
02378 }
02379 else if(strKey == "Scroll Lock")
02380 {
02381 value = ScrollLock;
02382 }
02383 else if(strKey == "Left Shift")
02384 {
02385 value = LeftShift;
02386 }
02387 else if(strKey == "Right Shift")
02388 {
02389 value = RightShift;
02390 }
02391 else if(strKey == "Left Control")
02392 {
02393 value = LeftControl;
02394 }
02395 else if(strKey == "Right Control")
02396 {
02397 value = RightControl;
02398 }
02399 else if(strKey == "Comma")
02400 {
02401 value = Comma;
02402 }
02403 else if(strKey == "Period")
02404 {
02405 value = Period;
02406 }
02407 else if(strKey == "Left Alt")
02408 {
02409 value = LeftAlt;
02410 }
02411 else if(strKey == "Right Alt")
02412 {
02413 value = RightAlt;
02414 }
02415 else
02416 {
02417 value = Invalid;
02418 }
02419
02420 return value;
02421 }
02422
02423 #ifdef WIN32
02424
02425
02426
02427
02428
02429
02430
02431
02432
02433
02434
02435
02436
02437
02438 int Keyboard::LookupScanCodeDX(const Key key)
02439 {
02440 unsigned int value = 0;
02441
02442 switch(key)
02443 {
02444 case Backspace:
02445 value = 0x0E;
02446 break;
02447 case Tab:
02448 value = 0x0F;
02449 break;
02450 case Return:
02451 value = 0x1C;
02452 break;
02453 case CapsLock:
02454 value = 0x3A;
02455 break;
02456 case Escape:
02457 value = 0x01;
02458 break;
02459 case Space:
02460 value = 0x39;
02461 break;
02462 case PageUp:
02463 value = 0xC9;
02464 break;
02465 case PageDown:
02466 value = 0xD1;
02467 break;
02468 case End:
02469 value = 0xCF;
02470 break;
02471 case Home:
02472 value = 0xC7;
02473 break;
02474 case LeftArrow:
02475 value = 0xCB;
02476 break;
02477 case UpArrow:
02478 value = 0xC8;
02479 break;
02480 case RightArrow:
02481 value = 0xCD;
02482 break;
02483 case DownArrow:
02484 value = 0xD0;
02485 break;
02486 case Insert:
02487 value = 0xD2;
02488 break;
02489 case Delete:
02490 value = 0xD3;
02491 break;
02492 case Zero:
02493 value = 0x0B;
02494 break;
02495 case One:
02496 value = 0x02;
02497 break;
02498 case Two:
02499 value = 0x03;
02500 break;
02501 case Three:
02502 value = 0x04;
02503 break;
02504 case Four:
02505 value = 0x05;
02506 break;
02507 case Five:
02508 value = 0x06;
02509 break;
02510 case Six:
02511 value = 0x07;
02512 break;
02513 case Seven:
02514 value = 0x08;
02515 break;
02516 case Eight:
02517 value = 0x09;
02518 break;
02519 case Nine:
02520 value = 0x0A;
02521 break;
02522 case A:
02523 value = 0x1E;
02524 break;
02525 case B:
02526 value = 0x30;
02527 break;
02528 case C:
02529 value = 0x2E;
02530 break;
02531 case D:
02532 value = 0x20;
02533 break;
02534 case E:
02535 value = 0x12;
02536 break;
02537 case F:
02538 value = 0x21;
02539 break;
02540 case G:
02541 value = 0x22;
02542 break;
02543 case H:
02544 value = 0x23;
02545 break;
02546 case I:
02547 value = 0x17;
02548 break;
02549 case J:
02550 value = 0x24;
02551 break;
02552 case K:
02553 value = 0x25;
02554 break;
02555 case L:
02556 value = 0x26;
02557 break;
02558 case M:
02559 value = 0x32;
02560 break;
02561 case N:
02562 value = 0x31;
02563 break;
02564 case O:
02565 value = 0x18;
02566 break;
02567 case P:
02568 value = 0x19;
02569 break;
02570 case Q:
02571 value = 0x10;
02572 break;
02573 case R:
02574 value = 0x13;
02575 break;
02576 case S:
02577 value = 0x1F;
02578 break;
02579 case T:
02580 value = 0x14;
02581 break;
02582 case U:
02583 value = 0x16;
02584 break;
02585 case V:
02586 value = 0x2F;
02587 break;
02588 case W:
02589 value = 0x11;
02590 break;
02591 case X:
02592 value = 0x2D;
02593 break;
02594 case Y:
02595 value = 0x15;
02596 break;
02597 case Z:
02598 value = 0x2C;
02599 break;
02600 case Numpad0:
02601 value = 0x52;
02602 break;
02603 case Numpad1:
02604 value = 0x4F;
02605 break;
02606 case Numpad2:
02607 value = 0x50;
02608 break;
02609 case Numpad3:
02610 value = 0x51;
02611 break;
02612 case Numpad4:
02613 value = 0x4B;
02614 break;
02615 case Numpad5:
02616 value = 0x4C;
02617 break;
02618 case Numpad6:
02619 value = 0x4D;
02620 break;
02621 case Numpad7:
02622 value = 0x47;
02623 break;
02624 case Numpad8:
02625 value = 0x48;
02626 break;
02627 case Numpad9:
02628 value = 0x49;
02629 break;
02630 case Multiply:
02631 value = 0x37;
02632 break;
02633 case Add:
02634 value = 0x4E;
02635 break;
02636 case Subtract:
02637 value = 0x4A;
02638 break;
02639 case Decimal:
02640 value = 0x53;
02641 break;
02642 case Divide:
02643 value = 0xB5;
02644 break;
02645 case F1:
02646 value = 0x3B;
02647 break;
02648 case F2:
02649 value = 0x3C;
02650 break;
02651 case F3:
02652 value = 0x3D;
02653 break;
02654 case F4:
02655 value = 0x3E;
02656 break;
02657 case F5:
02658 value = 0xEF;
02659 break;
02660 case F6:
02661 value = 0x40;
02662 break;
02663 case F7:
02664 value = 0x41;
02665 break;
02666 case F8:
02667 value = 0x42;
02668 break;
02669 case F9:
02670 value = 0x43;
02671 break;
02672 case F10:
02673 value = 0x44;
02674 break;
02675 case F11:
02676 value = 0x57;
02677 break;
02678 case F12:
02679 value = 0xF8;
02680 break;
02681 case NumLock:
02682 value = 0x45;
02683 break;
02684 case ScrollLock:
02685 value = 0x46;
02686 break;
02687 case LeftShift:
02688 value = 0x2A;
02689 break;
02690 case RightShift:
02691 value = 0x36;
02692 break;
02693 case LeftControl:
02694 value = 0x1D;
02695 break;
02696 case RightControl:
02697 value = 0x9D;
02698 break;
02699 case Comma:
02700 value = 0x33;
02701 break;
02702 case Period:
02703 value = 0x34;
02704 break;
02705 case LeftAlt:
02706 value = 0x38;
02707 break;
02708 case RightAlt:
02709 value = 0xB8;
02710 break;
02711 default:
02712 value = 0;
02713 break;
02714 }
02715 return value;
02716 }
02717
02718 #endif
02719
02720
02721