00001 00012 /*************************************************************************** 00013 * Copyright (C) 2007 by Jan Koci * 00014 * honza.koci@email.cz * 00015 * http://kengine.sourceforge.net/tutorial/ 00016 * * 00017 * This program is free software; you can redistribute it and/or modify * 00018 * it under the terms of the GNU General Public License as published by * 00019 * the Free Software Foundation; either version 2 of the License, or * 00020 * (at your option) any later version. * 00021 * * 00022 * This program is distributed in the hope that it will be useful, * 00023 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00025 * GNU General Public License for more details. * 00026 * * 00027 * You should have received a copy of the GNU General Public License * 00028 * along with this program; if not, write to the * 00029 * Free Software Foundation, Inc., * 00030 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00031 ***************************************************************************/ 00032 00033 #pragma once 00034 00035 #include <stdio.h> 00036 #include <iostream> 00037 using namespace std; 00038 #include <SDL/SDL.h> 00039 #include <SDL/SDL_opengl.h> 00040 #include <SDL/SDL_image.h> 00041 00042 class K3dKeyboard 00043 { 00044 Uint8* m_puiKeys; 00045 public: 00046 K3dKeyboard() 00047 { 00048 m_puiKeys = SDL_GetKeyState ( NULL ); 00049 } 00050 ~K3dKeyboard() {} 00051 00052 bool GetKeyEsc(); 00053 bool GetKeyF1(); 00054 bool GetKeyF2(); 00055 bool GetKeyF3(); 00056 bool GetKeyF4(); 00057 bool GetKeyF5(); 00058 bool GetKeyF6(); 00059 bool GetKeyF7(); 00060 bool GetKeyF8(); 00061 bool GetKeyF9(); 00062 bool GetKeyF10(); 00063 bool GetKeyF11(); 00064 bool GetKeyF12(); 00065 00066 bool GetKeyUp(); 00067 bool GetKeyDown(); 00068 bool GetKeyLeft(); 00069 bool GetKeyRight(); 00070 bool GetKeyPageUp(); 00071 bool GetKeyPageDown(); 00072 bool GetKeyHome(); 00073 bool GetKeyEnd(); 00074 bool GetKeyInsert(); 00075 bool GetKeyDelete(); 00076 00077 bool GetKeyConsole(); 00078 bool GetKey0(); 00079 bool GetKey1(); 00080 bool GetKey2(); 00081 bool GetKey3(); 00082 bool GetKey4(); 00083 bool GetKey5(); 00084 bool GetKey6(); 00085 bool GetKey7(); 00086 bool GetKey8(); 00087 bool GetKey9(); 00088 bool GetKeyA(); 00089 bool GetKeyB(); 00090 bool GetKeyC(); 00091 bool GetKeyD(); 00092 bool GetKeyE(); 00093 bool GetKeyF(); 00094 bool GetKeyG(); 00095 bool GetKeyH(); 00096 bool GetKeyI(); 00097 bool GetKeyJ(); 00098 bool GetKeyK(); 00099 bool GetKeyL(); 00100 bool GetKeyM(); 00101 bool GetKeyN(); 00102 bool GetKeyO(); 00103 bool GetKeyP(); 00104 bool GetKeyQ(); 00105 bool GetKeyR(); 00106 bool GetKeyS(); 00107 bool GetKeyT(); 00108 bool GetKeyU(); 00109 bool GetKeyV(); 00110 bool GetKeyW(); 00111 bool GetKeyX(); 00112 bool GetKeyY(); 00113 bool GetKeyZ(); 00114 00115 bool GetKeyPlus(); 00116 bool GetKeyMinus(); 00117 00118 bool GetKeyBackSpace(); 00119 bool GetKeyEnter(); 00120 bool GetKeySpace(); 00121 bool GetKeyLeftShift(); 00122 bool GetKeyRightShift(); 00123 bool GetKeyLeftCtrl(); 00124 bool GetKeyRightCtrl(); 00125 bool GetKeyLeftAlt(); 00126 bool GetKeyRightAlt(); 00127 00128 void UpdateKeyboard(); 00131 bool IsSdlKeyPressed ( const int _iSDLKey ) 00132 { 00133 if ( m_puiKeys[_iSDLKey] == SDL_PRESSED ) 00134 { 00135 return true; 00136 } 00137 else 00138 { 00139 return false; 00140 } 00141 } 00142 00143 }; 00144 00145 inline void K3dKeyboard::UpdateKeyboard() 00146 { 00147 SDL_PumpEvents(); 00148 } 00149 00150 00151 inline bool K3dKeyboard::GetKeyEsc() 00152 { 00153 if ( m_puiKeys[SDLK_ESCAPE] == SDL_PRESSED ) 00154 { 00155 return true; 00156 } 00157 else 00158 { 00159 return false; 00160 } 00161 } 00162 inline bool K3dKeyboard::GetKeyF1() 00163 { 00164 if ( m_puiKeys[SDLK_F1] == SDL_PRESSED ) 00165 { 00166 return true; 00167 } 00168 else 00169 { 00170 return false; 00171 } 00172 } 00173 inline bool K3dKeyboard::GetKeyF2() 00174 { 00175 if ( m_puiKeys[SDLK_F2] == SDL_PRESSED ) 00176 { 00177 return true; 00178 } 00179 else 00180 { 00181 return false; 00182 } 00183 } 00184 inline bool K3dKeyboard::GetKeyF3() 00185 { 00186 if ( m_puiKeys[SDLK_F3] == SDL_PRESSED ) 00187 { 00188 return true; 00189 } 00190 else 00191 { 00192 return false; 00193 } 00194 } 00195 inline bool K3dKeyboard::GetKeyF4() 00196 { 00197 if ( m_puiKeys[SDLK_F4] == SDL_PRESSED ) 00198 { 00199 return true; 00200 } 00201 else 00202 { 00203 return false; 00204 } 00205 } 00206 inline bool K3dKeyboard::GetKeyF5() 00207 { 00208 if ( m_puiKeys[SDLK_F5] == SDL_PRESSED ) 00209 { 00210 return true; 00211 } 00212 else 00213 { 00214 return false; 00215 } 00216 } 00217 inline bool K3dKeyboard::GetKeyF6() 00218 { 00219 if ( m_puiKeys[SDLK_F6] == SDL_PRESSED ) 00220 { 00221 return true; 00222 } 00223 else 00224 { 00225 return false; 00226 } 00227 } 00228 inline bool K3dKeyboard::GetKeyF7() 00229 { 00230 if ( m_puiKeys[SDLK_F7] == SDL_PRESSED ) 00231 { 00232 return true; 00233 } 00234 else 00235 { 00236 return false; 00237 } 00238 } 00239 inline bool K3dKeyboard::GetKeyF8() 00240 { 00241 if ( m_puiKeys[SDLK_F8] == SDL_PRESSED ) 00242 { 00243 return true; 00244 } 00245 else 00246 { 00247 return false; 00248 } 00249 } 00250 inline bool K3dKeyboard::GetKeyF9() 00251 { 00252 if ( m_puiKeys[SDLK_F9] == SDL_PRESSED ) 00253 { 00254 return true; 00255 } 00256 else 00257 { 00258 return false; 00259 } 00260 } 00261 inline bool K3dKeyboard::GetKeyF10() 00262 { 00263 if ( m_puiKeys[SDLK_F10] == SDL_PRESSED ) 00264 { 00265 return true; 00266 } 00267 else 00268 { 00269 return false; 00270 } 00271 } 00272 inline bool K3dKeyboard::GetKeyF11() 00273 { 00274 if ( m_puiKeys[SDLK_F11] == SDL_PRESSED ) 00275 { 00276 return true; 00277 } 00278 else 00279 { 00280 return false; 00281 } 00282 } 00283 inline bool K3dKeyboard::GetKeyF12() 00284 { 00285 if ( m_puiKeys[SDLK_F12] == SDL_PRESSED ) 00286 { 00287 return true; 00288 } 00289 else 00290 { 00291 return false; 00292 } 00293 } 00294 00295 inline bool K3dKeyboard::GetKeyUp() 00296 { 00297 if ( m_puiKeys[SDLK_UP] == SDL_PRESSED ) 00298 { 00299 return true; 00300 } 00301 else 00302 { 00303 return false; 00304 } 00305 } 00306 inline bool K3dKeyboard::GetKeyDown() 00307 { 00308 if ( m_puiKeys[SDLK_DOWN] == SDL_PRESSED ) 00309 { 00310 return true; 00311 } 00312 else 00313 { 00314 return false; 00315 } 00316 } 00317 inline bool K3dKeyboard::GetKeyLeft() 00318 { 00319 if ( m_puiKeys[SDLK_LEFT] == SDL_PRESSED ) 00320 { 00321 return true; 00322 } 00323 else 00324 { 00325 return false; 00326 } 00327 } 00328 inline bool K3dKeyboard::GetKeyRight() 00329 { 00330 if ( m_puiKeys[SDLK_RIGHT] == SDL_PRESSED ) 00331 { 00332 return true; 00333 } 00334 else 00335 { 00336 return false; 00337 } 00338 } 00339 inline bool K3dKeyboard::GetKeyPageUp() 00340 { 00341 if ( m_puiKeys[SDLK_PAGEUP] == SDL_PRESSED ) 00342 { 00343 return true; 00344 } 00345 else 00346 { 00347 return false; 00348 } 00349 } 00350 inline bool K3dKeyboard::GetKeyPageDown() 00351 { 00352 if ( m_puiKeys[SDLK_PAGEDOWN] == SDL_PRESSED ) 00353 { 00354 return true; 00355 } 00356 else 00357 { 00358 return false; 00359 } 00360 } 00361 inline bool K3dKeyboard::GetKeyHome() 00362 { 00363 if ( m_puiKeys[SDLK_HOME] == SDL_PRESSED ) 00364 { 00365 return true; 00366 } 00367 else 00368 { 00369 return false; 00370 } 00371 } 00372 inline bool K3dKeyboard::GetKeyEnd() 00373 { 00374 if ( m_puiKeys[SDLK_END] == SDL_PRESSED ) 00375 { 00376 return true; 00377 } 00378 else 00379 { 00380 return false; 00381 } 00382 } 00383 inline bool K3dKeyboard::GetKeyInsert() 00384 { 00385 if ( m_puiKeys[SDLK_INSERT] == SDL_PRESSED ) 00386 { 00387 return true; 00388 } 00389 else 00390 { 00391 return false; 00392 } 00393 } 00394 inline bool K3dKeyboard::GetKeyDelete() 00395 { 00396 if ( m_puiKeys[SDLK_DELETE] == SDL_PRESSED ) 00397 { 00398 return true; 00399 } 00400 else 00401 { 00402 return false; 00403 } 00404 } 00405 00406 inline bool K3dKeyboard::GetKeyConsole() 00407 { 00408 if ( m_puiKeys[SDLK_BACKQUOTE] == SDL_PRESSED ) 00409 { 00410 return true; 00411 } 00412 else 00413 { 00414 return false; 00415 } 00416 } 00417 inline bool K3dKeyboard::GetKey0() 00418 { 00419 if ( m_puiKeys[SDLK_KP0] == SDL_PRESSED ) 00420 { 00421 return true; 00422 } 00423 else 00424 { 00425 return false; 00426 } 00427 } 00428 inline bool K3dKeyboard::GetKey1() 00429 { 00430 if ( m_puiKeys[SDLK_KP1] == SDL_PRESSED ) 00431 { 00432 return true; 00433 } 00434 else 00435 { 00436 return false; 00437 } 00438 } 00439 inline bool K3dKeyboard::GetKey2() 00440 { 00441 if ( m_puiKeys[SDLK_KP2] == SDL_PRESSED ) 00442 { 00443 return true; 00444 } 00445 else 00446 { 00447 return false; 00448 } 00449 } 00450 inline bool K3dKeyboard::GetKey3() 00451 { 00452 if ( m_puiKeys[SDLK_KP3] == SDL_PRESSED ) 00453 { 00454 return true; 00455 } 00456 else 00457 { 00458 return false; 00459 } 00460 } 00461 inline bool K3dKeyboard::GetKey4() 00462 { 00463 if ( m_puiKeys[SDLK_KP4] == SDL_PRESSED ) 00464 { 00465 return true; 00466 } 00467 else 00468 { 00469 return false; 00470 } 00471 } 00472 inline bool K3dKeyboard::GetKey5() 00473 { 00474 if ( m_puiKeys[SDLK_KP5] == SDL_PRESSED ) 00475 { 00476 return true; 00477 } 00478 else 00479 { 00480 return false; 00481 } 00482 } 00483 inline bool K3dKeyboard::GetKey6() 00484 { 00485 if ( m_puiKeys[SDLK_KP6] == SDL_PRESSED ) 00486 { 00487 return true; 00488 } 00489 else 00490 { 00491 return false; 00492 } 00493 } 00494 inline bool K3dKeyboard::GetKey7() 00495 { 00496 if ( m_puiKeys[SDLK_KP7] == SDL_PRESSED ) 00497 { 00498 return true; 00499 } 00500 else 00501 { 00502 return false; 00503 } 00504 } 00505 inline bool K3dKeyboard::GetKey8() 00506 { 00507 if ( m_puiKeys[SDLK_KP8] == SDL_PRESSED ) 00508 { 00509 return true; 00510 } 00511 else 00512 { 00513 return false; 00514 } 00515 } 00516 inline bool K3dKeyboard::GetKey9() 00517 { 00518 if ( m_puiKeys[SDLK_KP9] == SDL_PRESSED ) 00519 { 00520 return true; 00521 } 00522 else 00523 { 00524 return false; 00525 } 00526 } 00527 00528 inline bool K3dKeyboard::GetKeyA() 00529 { 00530 if ( m_puiKeys[SDLK_a] == SDL_PRESSED ) 00531 { 00532 return true; 00533 } 00534 else 00535 { 00536 return false; 00537 } 00538 } 00539 inline bool K3dKeyboard::GetKeyB() 00540 { 00541 if ( m_puiKeys[SDLK_b] == SDL_PRESSED ) 00542 { 00543 return true; 00544 } 00545 else 00546 { 00547 return false; 00548 } 00549 } 00550 inline bool K3dKeyboard::GetKeyC() 00551 { 00552 if ( m_puiKeys[SDLK_c] == SDL_PRESSED ) 00553 { 00554 return true; 00555 } 00556 else 00557 { 00558 return false; 00559 } 00560 } 00561 inline bool K3dKeyboard::GetKeyD() 00562 { 00563 if ( m_puiKeys[SDLK_d] == SDL_PRESSED ) 00564 { 00565 return true; 00566 } 00567 else 00568 { 00569 return false; 00570 } 00571 } 00572 inline bool K3dKeyboard::GetKeyE() 00573 { 00574 if ( m_puiKeys[SDLK_e] == SDL_PRESSED ) 00575 { 00576 return true; 00577 } 00578 else 00579 { 00580 return false; 00581 } 00582 } 00583 inline bool K3dKeyboard::GetKeyF() 00584 { 00585 if ( m_puiKeys[SDLK_f] == SDL_PRESSED ) 00586 { 00587 return true; 00588 } 00589 else 00590 { 00591 return false; 00592 } 00593 } 00594 inline bool K3dKeyboard::GetKeyG() 00595 { 00596 if ( m_puiKeys[SDLK_g] == SDL_PRESSED ) 00597 { 00598 return true; 00599 } 00600 else 00601 { 00602 return false; 00603 } 00604 } 00605 inline bool K3dKeyboard::GetKeyH() 00606 { 00607 if ( m_puiKeys[SDLK_h] == SDL_PRESSED ) 00608 { 00609 return true; 00610 } 00611 else 00612 { 00613 return false; 00614 } 00615 } 00616 inline bool K3dKeyboard::GetKeyI() 00617 { 00618 if ( m_puiKeys[SDLK_i] == SDL_PRESSED ) 00619 { 00620 return true; 00621 } 00622 else 00623 { 00624 return false; 00625 } 00626 } 00627 inline bool K3dKeyboard::GetKeyJ() 00628 { 00629 if ( m_puiKeys[SDLK_j] == SDL_PRESSED ) 00630 { 00631 return true; 00632 } 00633 else 00634 { 00635 return false; 00636 } 00637 } 00638 inline bool K3dKeyboard::GetKeyK() 00639 { 00640 if ( m_puiKeys[SDLK_k] == SDL_PRESSED ) 00641 { 00642 return true; 00643 } 00644 else 00645 { 00646 return false; 00647 } 00648 } 00649 inline bool K3dKeyboard::GetKeyL() 00650 { 00651 if ( m_puiKeys[SDLK_l] == SDL_PRESSED ) 00652 { 00653 return true; 00654 } 00655 else 00656 { 00657 return false; 00658 } 00659 } 00660 inline bool K3dKeyboard::GetKeyM() 00661 { 00662 if ( m_puiKeys[SDLK_m] == SDL_PRESSED ) 00663 { 00664 return true; 00665 } 00666 else 00667 { 00668 return false; 00669 } 00670 } 00671 inline bool K3dKeyboard::GetKeyN() 00672 { 00673 if ( m_puiKeys[SDLK_n] == SDL_PRESSED ) 00674 { 00675 return true; 00676 } 00677 else 00678 { 00679 return false; 00680 } 00681 } 00682 inline bool K3dKeyboard::GetKeyO() 00683 { 00684 if ( m_puiKeys[SDLK_o] == SDL_PRESSED ) 00685 { 00686 return true; 00687 } 00688 else 00689 { 00690 return false; 00691 } 00692 } 00693 inline bool K3dKeyboard::GetKeyP() 00694 { 00695 if ( m_puiKeys[SDLK_p] == SDL_PRESSED ) 00696 { 00697 return true; 00698 } 00699 else 00700 { 00701 return false; 00702 } 00703 } 00704 inline bool K3dKeyboard::GetKeyQ() 00705 { 00706 if ( m_puiKeys[SDLK_q] == SDL_PRESSED ) 00707 { 00708 return true; 00709 } 00710 else 00711 { 00712 return false; 00713 } 00714 } 00715 inline bool K3dKeyboard::GetKeyR() 00716 { 00717 if ( m_puiKeys[SDLK_r] == SDL_PRESSED ) 00718 { 00719 return true; 00720 } 00721 else 00722 { 00723 return false; 00724 } 00725 } 00726 inline bool K3dKeyboard::GetKeyS() 00727 { 00728 if ( m_puiKeys[SDLK_s] == SDL_PRESSED ) 00729 { 00730 return true; 00731 } 00732 else 00733 { 00734 return false; 00735 } 00736 } 00737 inline bool K3dKeyboard::GetKeyT() 00738 { 00739 if ( m_puiKeys[SDLK_t] == SDL_PRESSED ) 00740 { 00741 return true; 00742 } 00743 else 00744 { 00745 return false; 00746 } 00747 } 00748 inline bool K3dKeyboard::GetKeyU() 00749 { 00750 if ( m_puiKeys[SDLK_u] == SDL_PRESSED ) 00751 { 00752 return true; 00753 } 00754 else 00755 { 00756 return false; 00757 } 00758 } 00759 inline bool K3dKeyboard::GetKeyV() 00760 { 00761 if ( m_puiKeys[SDLK_v] == SDL_PRESSED ) 00762 { 00763 return true; 00764 } 00765 else 00766 { 00767 return false; 00768 } 00769 } 00770 inline bool K3dKeyboard::GetKeyW() 00771 { 00772 if ( m_puiKeys[SDLK_w] == SDL_PRESSED ) 00773 { 00774 return true; 00775 } 00776 else 00777 { 00778 return false; 00779 } 00780 } 00781 inline bool K3dKeyboard::GetKeyX() 00782 { 00783 if ( m_puiKeys[SDLK_x] == SDL_PRESSED ) 00784 { 00785 return true; 00786 } 00787 else 00788 { 00789 return false; 00790 } 00791 } 00792 inline bool K3dKeyboard::GetKeyY() 00793 { 00794 if ( m_puiKeys[SDLK_y] == SDL_PRESSED ) 00795 { 00796 return true; 00797 } 00798 else 00799 { 00800 return false; 00801 } 00802 } 00803 inline bool K3dKeyboard::GetKeyZ() 00804 { 00805 if ( m_puiKeys[SDLK_z] == SDL_PRESSED ) 00806 { 00807 return true; 00808 } 00809 else 00810 { 00811 return false; 00812 } 00813 } 00814 00815 inline bool K3dKeyboard::GetKeyPlus() 00816 { 00817 if ( m_puiKeys[SDLK_PLUS] == SDL_PRESSED ) 00818 { 00819 return true; 00820 } 00821 else 00822 { 00823 return false; 00824 } 00825 } 00826 inline bool K3dKeyboard::GetKeyMinus() 00827 { 00828 if ( m_puiKeys[SDLK_MINUS] == SDL_PRESSED ) 00829 { 00830 return true; 00831 } 00832 else 00833 { 00834 return false; 00835 } 00836 } 00837 00838 inline bool K3dKeyboard::GetKeyBackSpace() 00839 { 00840 if ( m_puiKeys[SDLK_BACKSPACE] == SDL_PRESSED ) 00841 { 00842 return true; 00843 } 00844 else 00845 { 00846 return false; 00847 } 00848 } 00849 00850 inline bool K3dKeyboard::GetKeyEnter() 00851 { 00852 if ( m_puiKeys[SDLK_KP_ENTER] == SDL_PRESSED ) 00853 { 00854 return true; 00855 } 00856 else 00857 { 00858 return false; 00859 } 00860 } 00861 inline bool K3dKeyboard::GetKeySpace() 00862 { 00863 if ( m_puiKeys[SDLK_SPACE] == SDL_PRESSED ) 00864 { 00865 return true; 00866 } 00867 else 00868 { 00869 return false; 00870 } 00871 } 00872 inline bool K3dKeyboard::GetKeyLeftShift() 00873 { 00874 if ( m_puiKeys[SDLK_LSHIFT] == SDL_PRESSED ) 00875 { 00876 return true; 00877 } 00878 else 00879 { 00880 return false; 00881 } 00882 } 00883 inline bool K3dKeyboard::GetKeyRightShift() 00884 { 00885 if ( m_puiKeys[SDLK_RSHIFT] == SDL_PRESSED ) 00886 { 00887 return true; 00888 } 00889 else 00890 { 00891 return false; 00892 } 00893 } 00894 inline bool K3dKeyboard::GetKeyLeftCtrl() 00895 { 00896 if ( m_puiKeys[SDLK_LCTRL] == SDL_PRESSED ) 00897 { 00898 return true; 00899 } 00900 else 00901 { 00902 return false; 00903 } 00904 } 00905 inline bool K3dKeyboard::GetKeyRightCtrl() 00906 { 00907 if ( m_puiKeys[SDLK_RCTRL] == SDL_PRESSED ) 00908 { 00909 return true; 00910 } 00911 else 00912 { 00913 return false; 00914 } 00915 } 00916 inline bool K3dKeyboard::GetKeyLeftAlt() 00917 { 00918 if ( m_puiKeys[SDLK_LALT] == SDL_PRESSED ) 00919 { 00920 return true; 00921 } 00922 else 00923 { 00924 return false; 00925 } 00926 } 00927 inline bool K3dKeyboard::GetKeyRightAlt() 00928 { 00929 if ( m_puiKeys[SDLK_RALT] == SDL_PRESSED ) 00930 { 00931 return true; 00932 } 00933 else 00934 { 00935 return false; 00936 } 00937 } 00938 00939