| 1 | /* | 
|---|
| 2 | *   ORXONOX - the hottest 3D action shooter ever to exist | 
|---|
| 3 | *                    > www.orxonox.net < | 
|---|
| 4 | * | 
|---|
| 5 | * | 
|---|
| 6 | *   License notice: | 
|---|
| 7 | * | 
|---|
| 8 | *   This program is free software; you can redistribute it and/or | 
|---|
| 9 | *   modify it under the terms of the GNU General Public License | 
|---|
| 10 | *   as published by the Free Software Foundation; either version 2 | 
|---|
| 11 | *   of the License, or (at your option) any later version. | 
|---|
| 12 | * | 
|---|
| 13 | *   This program is distributed in the hope that it will be useful, | 
|---|
| 14 | *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 15 | *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 16 | *   GNU General Public License for more details. | 
|---|
| 17 | * | 
|---|
| 18 | *   You should have received a copy of the GNU General Public License | 
|---|
| 19 | *   along with this program; if not, write to the Free Software | 
|---|
| 20 | *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
|---|
| 21 | * | 
|---|
| 22 | *   Author: | 
|---|
| 23 | *      Reto Grieder | 
|---|
| 24 | *   Co-authors: | 
|---|
| 25 | *      ... | 
|---|
| 26 | * | 
|---|
| 27 | */ | 
|---|
| 28 |  | 
|---|
| 29 | #include "Keyboard.h" | 
|---|
| 30 | #include "InputState.h" | 
|---|
| 31 |  | 
|---|
| 32 | namespace orxonox | 
|---|
| 33 | { | 
|---|
| 34 | //! OIS event handler | 
|---|
| 35 | bool Keyboard::keyPressed(const OIS::KeyEvent& arg) | 
|---|
| 36 | { | 
|---|
| 37 | // update modifiers | 
|---|
| 38 | switch (arg.key) | 
|---|
| 39 | { | 
|---|
| 40 | case OIS::KC_RMENU: | 
|---|
| 41 | case OIS::KC_LMENU: | 
|---|
| 42 | modifiers_ |= KeyboardModifier::Alt;   // alt key | 
|---|
| 43 | break; | 
|---|
| 44 | case OIS::KC_RCONTROL: | 
|---|
| 45 | case OIS::KC_LCONTROL: | 
|---|
| 46 | modifiers_ |= KeyboardModifier::Ctrl;  // ctrl key | 
|---|
| 47 | break; | 
|---|
| 48 | case OIS::KC_RSHIFT: | 
|---|
| 49 | case OIS::KC_LSHIFT: | 
|---|
| 50 | modifiers_ |= KeyboardModifier::Shift; // shift key | 
|---|
| 51 | break; | 
|---|
| 52 | case OIS::KC_TAB: | 
|---|
| 53 | // Do not distribute the alt+tab event (messes with the operating system) | 
|---|
| 54 | if ((modifiers_ & KeyboardModifier::Alt) != 0) | 
|---|
| 55 | return true; | 
|---|
| 56 | default:; | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | KeyEvent evt(static_cast<KeyCode::ByEnum>(arg.key), Keyboard::getKeyText(arg), 0); | 
|---|
| 60 | super::buttonPressed(evt); | 
|---|
| 61 | return true; | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | //! OIS event handler | 
|---|
| 65 | bool Keyboard::keyReleased(const OIS::KeyEvent& arg) | 
|---|
| 66 | { | 
|---|
| 67 | // update modifiers | 
|---|
| 68 | switch (arg.key) | 
|---|
| 69 | { | 
|---|
| 70 | case OIS::KC_RMENU: | 
|---|
| 71 | case OIS::KC_LMENU: | 
|---|
| 72 | modifiers_ &= ~KeyboardModifier::Alt;   // alt key | 
|---|
| 73 | break; | 
|---|
| 74 | case OIS::KC_RCONTROL: | 
|---|
| 75 | case OIS::KC_LCONTROL: | 
|---|
| 76 | modifiers_ &= ~KeyboardModifier::Ctrl;  // ctrl key | 
|---|
| 77 | break; | 
|---|
| 78 | case OIS::KC_RSHIFT: | 
|---|
| 79 | case OIS::KC_LSHIFT: | 
|---|
| 80 | modifiers_ &= ~KeyboardModifier::Shift; // shift key | 
|---|
| 81 | break; | 
|---|
| 82 | default:; | 
|---|
| 83 | } | 
|---|
| 84 |  | 
|---|
| 85 | KeyEvent evt(static_cast<KeyCode::ByEnum>(arg.key), Keyboard::getKeyText(arg), 0); | 
|---|
| 86 | super::buttonReleased(evt); | 
|---|
| 87 | return true; | 
|---|
| 88 | } | 
|---|
| 89 |  | 
|---|
| 90 | /// A map which returns the corresponding chars for some key codes | 
|---|
| 91 | unsigned int Keyboard::getKeyText(const OIS::KeyEvent& arg) | 
|---|
| 92 | { | 
|---|
| 93 | switch (arg.key) | 
|---|
| 94 | { | 
|---|
| 95 | case OIS::KC_NUMPAD0:     return static_cast<unsigned int>('0'); | 
|---|
| 96 | case OIS::KC_NUMPAD1:     return static_cast<unsigned int>('1'); | 
|---|
| 97 | case OIS::KC_NUMPAD2:     return static_cast<unsigned int>('2'); | 
|---|
| 98 | case OIS::KC_NUMPAD3:     return static_cast<unsigned int>('3'); | 
|---|
| 99 | case OIS::KC_NUMPAD4:     return static_cast<unsigned int>('4'); | 
|---|
| 100 | case OIS::KC_NUMPAD5:     return static_cast<unsigned int>('5'); | 
|---|
| 101 | case OIS::KC_NUMPAD6:     return static_cast<unsigned int>('6'); | 
|---|
| 102 | case OIS::KC_NUMPAD7:     return static_cast<unsigned int>('7'); | 
|---|
| 103 | case OIS::KC_NUMPAD8:     return static_cast<unsigned int>('8'); | 
|---|
| 104 | case OIS::KC_NUMPAD9:     return static_cast<unsigned int>('9'); | 
|---|
| 105 | case OIS::KC_DECIMAL:     return static_cast<unsigned int>('.'); | 
|---|
| 106 | case OIS::KC_DIVIDE:      return static_cast<unsigned int>('/'); | 
|---|
| 107 | case OIS::KC_NUMPADENTER: return static_cast<unsigned int>('\n'); | 
|---|
| 108 | default:                  return arg.text; | 
|---|
| 109 | } | 
|---|
| 110 | } | 
|---|
| 111 | } | 
|---|