00001 /* 00002 The zlib/libpng License 00003 00004 Copyright (c) 2006 Chris Snyder 00005 00006 This software is provided 'as-is', without any express or implied warranty. In no event will 00007 the authors be held liable for any damages arising from the use of this software. 00008 00009 Permission is granted to anyone to use this software for any purpose, including commercial 00010 applications, and to alter it and redistribute it freely, subject to the following 00011 restrictions: 00012 00013 1. The origin of this software must not be misrepresented; you must not claim that 00014 you wrote the original software. If you use this software in a product, 00015 an acknowledgment in the product documentation would be appreciated but is 00016 not required. 00017 00018 2. Altered source versions must be plainly marked as such, and must not be 00019 misrepresented as being the original software. 00020 00021 3. This notice may not be removed or altered from any source distribution. 00022 */ 00023 #ifndef OIS_MacKeyboard_H 00024 #define OIS_MacKeyboard_H 00025 00026 #include "OISKeyboard.h" 00027 #include "mac/MacHelpers.h" 00028 #include "mac/MacPrereqs.h" 00029 00030 #include <Carbon/Carbon.h> 00031 00032 namespace OIS 00033 { 00034 00035 class MacKeyboard : public Keyboard 00036 { 00037 public: 00038 MacKeyboard( InputManager* creator, bool buffered, bool repeat ); 00039 virtual ~MacKeyboard(); 00040 00041 // Sets buffered mode 00042 virtual void setBuffered( bool buffered ); 00043 00044 // unbuffered keydown check 00045 virtual bool isKeyDown( KeyCode key ); 00046 00047 // This will send listener events if buffered is on. 00048 // Note that in the mac implementation, unbuffered input is 00049 // automatically updated without calling this. 00050 virtual void capture(); 00051 00052 // Copies the current key buffer 00053 virtual void copyKeyStates( char keys[256] ); 00054 00055 // Returns a description of the given key 00056 virtual std::string& getAsString( KeyCode key ); 00057 00058 virtual Interface* queryInterface( Interface::IType type ) { return 0; } 00059 00060 00061 // Public but reserved for internal use: 00062 virtual void _initialize(); 00063 void _keyDownCallback( EventRef theEvent ); 00064 void _keyUpCallback( EventRef theEvent ); 00065 void _modChangeCallback( EventRef theEvent ); 00066 00067 00068 protected: 00069 // just to get this out of the way 00070 void populateKeyConversion(); 00071 00072 // updates the keybuffer and optionally the eventStack 00073 void injectEvent(KeyCode kc, unsigned int time, MacEventType type, unsigned int txt = 0 ); 00074 00075 typedef std::map<UInt32, KeyCode> VirtualtoOIS_KeyMap; 00076 VirtualtoOIS_KeyMap keyConversion; 00077 00078 std::string getString; 00079 00080 char KeyBuffer[256]; 00081 UInt32 prevModMask; 00082 00083 00084 // "universal procedure pointers" - required reference for callbacks 00085 EventHandlerUPP keyDownUPP; 00086 EventHandlerUPP keyUpUPP; 00087 EventHandlerUPP keyModUPP; 00088 00089 // so we can delete the handlers on destruction 00090 EventHandlerRef keyDownEventRef; 00091 EventHandlerRef keyUpEventRef; 00092 EventHandlerRef keyModEventRef; 00093 00094 // buffered events, fifo stack 00095 typedef std::list<MacKeyStackEvent> eventStack; 00096 eventStack pendingEvents; 00097 00098 bool useRepeat; 00099 00100 }; 00101 00102 00103 00104 } 00105 #endif
1.5.4