Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreInput.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright © 2000-2002 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 #ifndef __Input_H__
00026 #define __Input_H__
00027 
00028 #include "OgrePrerequisites.h"
00029 
00030 namespace Ogre {
00031 
00032 //    typedef HashMap<int, char> KeyChars;
00033     typedef std::map<long, char> KeyChars;
00034 
00035     inline long KEYCODE(long keyCode, long modifiers = 0)
00036       { return ((modifiers << 16) & 0xffff0000) | (keyCode & 0xffff); }
00037 
00040     enum KeyCode
00041     {
00042         KC_ESCAPE          =0x01,
00043         KC_1               =0x02,
00044         KC_2               =0x03,
00045         KC_3               =0x04,
00046         KC_4               =0x05,
00047         KC_5               =0x06,
00048         KC_6               =0x07,
00049         KC_7               =0x08,
00050         KC_8               =0x09,
00051         KC_9               =0x0A,
00052         KC_0               =0x0B,
00053         KC_MINUS           =0x0C,    /* - on main keyboard */
00054         KC_EQUALS          =0x0D,
00055         KC_BACK            =0x0E,    /* backspace */
00056         KC_TAB             =0x0F,
00057         KC_Q               =0x10,
00058         KC_W               =0x11,
00059         KC_E               =0x12,
00060         KC_R               =0x13,
00061         KC_T               =0x14,
00062         KC_Y               =0x15,
00063         KC_U               =0x16,
00064         KC_I               =0x17,
00065         KC_O               =0x18,
00066         KC_P               =0x19,
00067         KC_LBRACKET        =0x1A,
00068         KC_RBRACKET        =0x1B,
00069         KC_RETURN          =0x1C,    /* Enter on main keyboard */
00070         KC_LCONTROL        =0x1D,
00071         KC_A               =0x1E,
00072         KC_S               =0x1F,
00073         KC_D               =0x20,
00074         KC_F               =0x21,
00075         KC_G               =0x22,
00076         KC_H               =0x23,
00077         KC_J               =0x24,
00078         KC_K               =0x25,
00079         KC_L               =0x26,
00080         KC_SEMICOLON       =0x27,
00081         KC_APOSTROPHE      =0x28,
00082         KC_GRAVE           =0x29,    /* accent grave */
00083         KC_LSHIFT          =0x2A,
00084         KC_BACKSLASH       =0x2B,
00085         KC_Z               =0x2C,
00086         KC_X               =0x2D,
00087         KC_C               =0x2E,
00088         KC_V               =0x2F,
00089         KC_B               =0x30,
00090         KC_N               =0x31,
00091         KC_M               =0x32,
00092         KC_COMMA           =0x33,
00093         KC_PERIOD          =0x34,    /* . on main keyboard */
00094         KC_SLASH           =0x35,    /* '/' on main keyboard */
00095         KC_RSHIFT          =0x36,
00096         KC_MULTIPLY        =0x37,    /* * on numeric keypad */
00097         KC_LMENU           =0x38,    /* left Alt */
00098         KC_SPACE           =0x39,
00099         KC_CAPITAL         =0x3A,
00100         KC_F1              =0x3B,
00101         KC_F2              =0x3C,
00102         KC_F3              =0x3D,
00103         KC_F4              =0x3E,
00104         KC_F5              =0x3F,
00105         KC_F6              =0x40,
00106         KC_F7              =0x41,
00107         KC_F8              =0x42,
00108         KC_F9              =0x43,
00109         KC_F10             =0x44,
00110         KC_NUMLOCK         =0x45,
00111         KC_SCROLL          =0x46,    /* Scroll Lock */
00112         KC_NUMPAD7         =0x47,
00113         KC_NUMPAD8         =0x48,
00114         KC_NUMPAD9         =0x49,
00115         KC_SUBTRACT        =0x4A,    /* - on numeric keypad */
00116         KC_NUMPAD4         =0x4B,
00117         KC_NUMPAD5         =0x4C,
00118         KC_NUMPAD6         =0x4D,
00119         KC_ADD             =0x4E,    /* + on numeric keypad */
00120         KC_NUMPAD1         =0x4F,
00121         KC_NUMPAD2         =0x50,
00122         KC_NUMPAD3         =0x51,
00123         KC_NUMPAD0         =0x52,
00124         KC_DECIMAL         =0x53,    /* . on numeric keypad */
00125         KC_OEM_102         =0x56,    /* < > | on UK/Germany keyboards */
00126         KC_F11             =0x57,
00127         KC_F12             =0x58,
00128         KC_F13             =0x64,    /*                     (NEC PC98) */
00129         KC_F14             =0x65,    /*                     (NEC PC98) */
00130         KC_F15             =0x66,    /*                     (NEC PC98) */
00131         KC_KANA            =0x70,    /* (Japanese keyboard)            */
00132         KC_ABNT_C1         =0x73,    /* / ? on Portugese (Brazilian) keyboards */
00133         KC_CONVERT         =0x79,    /* (Japanese keyboard)            */
00134         KC_NOCONVERT       =0x7B,    /* (Japanese keyboard)            */
00135         KC_YEN             =0x7D,    /* (Japanese keyboard)            */
00136         KC_ABNT_C2         =0x7E,    /* Numpad . on Portugese (Brazilian) keyboards */
00137         KC_NUMPADEQUALS    =0x8D,    /* = on numeric keypad (NEC PC98) */
00138         KC_PREVTRACK       =0x90,    /* Previous Track (KC_CIRCUMFLEX on Japanese keyboard) */
00139         KC_AT              =0x91,    /*                     (NEC PC98) */
00140         KC_COLON           =0x92,    /*                     (NEC PC98) */
00141         KC_UNDERLINE       =0x93,    /*                     (NEC PC98) */
00142         KC_KANJI           =0x94,    /* (Japanese keyboard)            */
00143         KC_STOP            =0x95,    /*                     (NEC PC98) */
00144         KC_AX              =0x96,    /*                     (Japan AX) */
00145         KC_UNLABELED       =0x97,    /*                        (J3100) */
00146         KC_NEXTTRACK       =0x99,    /* Next Track */
00147         KC_NUMPADENTER     =0x9C,    /* Enter on numeric keypad */
00148         KC_RCONTROL        =0x9D,
00149         KC_MUTE            =0xA0,    /* Mute */
00150         KC_CALCULATOR      =0xA1,    /* Calculator */
00151         KC_PLAYPAUSE       =0xA2,    /* Play / Pause */
00152         KC_MEDIASTOP       =0xA4,    /* Media Stop */
00153         KC_VOLUMEDOWN      =0xAE,    /* Volume - */
00154         KC_VOLUMEUP        =0xB0,    /* Volume + */
00155         KC_WEBHOME         =0xB2,    /* Web home */
00156         KC_NUMPADCOMMA     =0xB3,    /* , on numeric keypad (NEC PC98) */
00157         KC_DIVIDE          =0xB5,    /* / on numeric keypad */
00158         KC_SYSRQ           =0xB7,
00159         KC_RMENU           =0xB8,    /* right Alt */
00160         KC_PAUSE           =0xC5,    /* Pause */
00161         KC_HOME            =0xC7,    /* Home on arrow keypad */
00162         KC_UP              =0xC8,    /* UpArrow on arrow keypad */
00163         KC_PGUP            =0xC9,    /* PgUp on arrow keypad */
00164         KC_LEFT            =0xCB,    /* LeftArrow on arrow keypad */
00165         KC_RIGHT           =0xCD,    /* RightArrow on arrow keypad */
00166         KC_END             =0xCF,    /* End on arrow keypad */
00167         KC_DOWN            =0xD0,    /* DownArrow on arrow keypad */
00168         KC_PGDOWN          =0xD1,    /* PgDn on arrow keypad */
00169         KC_INSERT          =0xD2,    /* Insert on arrow keypad */
00170         KC_DELETE          =0xD3,    /* Delete on arrow keypad */
00171         KC_LWIN            =0xDB,    /* Left Windows key */
00172         KC_RWIN            =0xDC,    /* Right Windows key */
00173         KC_APPS            =0xDD,    /* AppMenu key */
00174         KC_POWER           =0xDE,    /* System Power */
00175         KC_SLEEP           =0xDF,    /* System Sleep */
00176         KC_WAKE            =0xE3,    /* System Wake */
00177         KC_WEBSEARCH       =0xE5,    /* Web Search */
00178         KC_WEBFAVORITES    =0xE6,    /* Web Favorites */
00179         KC_WEBREFRESH      =0xE7,    /* Web Refresh */
00180         KC_WEBSTOP         =0xE8,    /* Web Stop */
00181         KC_WEBFORWARD      =0xE9,    /* Web Forward */
00182         KC_WEBBACK         =0xEA,    /* Web Back */
00183         KC_MYCOMPUTER      =0xEB,    /* My Computer */
00184         KC_MAIL            =0xEC,    /* Mail */
00185         KC_MEDIASELECT     =0xED     /* Media Select */
00186     };
00187 
00190     struct _OgreExport MouseState
00191     {
00193         long Xabs, Yabs, Zabs;
00195         long Xrel, Yrel, Zrel;
00198         long Buttons;
00199 
00201         inline long isButtonDown( uchar button ) const
00202         {
00203             return Buttons & ( 1 << button );
00204         }
00205     };
00206 
00218     class _OgreExport InputReader
00219     {
00220     public:
00221         InputReader();
00222         virtual ~InputReader();
00223 
00230         void useBufferedInput(EventQueue* pEventQueue, bool keys = true, bool mouse = true) ;
00231 
00232         virtual void setBufferedInput(bool keys, bool mouse) ;
00233             
00234 
00247         virtual void initialise( 
00248             RenderWindow* pWindow, 
00249             bool useKeyboard = true, 
00250             bool useMouse = true, 
00251             bool useGameController = false ) = 0;
00252 
00262         virtual void capture() = 0;
00263 
00268         virtual bool isKeyDown( KeyCode kc ) const = 0;
00269 
00272         virtual long getMouseRelativeX() const { return getMouseRelX(); }
00273 
00276         virtual long getMouseRelativeY() const { return getMouseRelY(); }
00277 
00280         virtual long getMouseRelativeZ() const { return getMouseRelZ(); }
00281 
00284         virtual long getMouseRelX() const = 0;
00285 
00288         virtual long getMouseRelY() const = 0;
00289 
00292         virtual long getMouseRelZ() const = 0;
00293 
00295         virtual long getMouseAbsX() const = 0;
00297         virtual long getMouseAbsY() const = 0;
00299         virtual long getMouseAbsZ() const = 0;
00300 
00302         virtual void getMouseState( MouseState& state ) const = 0;
00303 
00305         virtual bool getMouseButton( uchar button ) const = 0;
00306 
00309         void addCursorMoveListener( MouseMotionListener* c );
00310     
00313         void removeCursorMoveListener( MouseMotionListener* c );
00314         static char getKeyChar(int keyCode, long modifiers = 0);
00315 
00316 
00317     protected:
00318 
00321         long mModifiers;
00322 
00323 //      static KeyChars sKeyChars;
00324         static bool sKeysInitialised;
00331         Cursor* mCursor;
00332 
00334         EventQueue* mEventQueue;
00335 
00339         bool mUseBufferedKeys, mUseBufferedMouse;
00340 
00342         MouseState mMouseState;
00343         
00344     protected:
00346         void mouseMoved();
00347 
00350         void createMouseEvent(int id, int button);
00351 
00353         void triggerMouseButton(int nMouseCode, bool mousePressed);
00354 
00355         void createKeyEvent(int id, int key);
00356         void keyChanged(int key, bool down);
00357         void setupKeyChars();
00358     };
00359 
00360 
00368     typedef void (*DLL_CREATEINPUTREADER)(InputReader** ppReader);
00369 
00370 }
00371 
00372 #endif

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:14 2004