Orxonox  0.0.5 Codename: Arcturus
MacKeyboard.h
Go to the documentation of this file.
1 /*
2  The zlib/libpng License
3 
4  Copyright (c) 2006 Chris Snyder
5 
6  This software is provided 'as-is', without any express or implied warranty. In no event will
7  the authors be held liable for any damages arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose, including commercial
10  applications, and to alter it and redistribute it freely, subject to the following
11  restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not claim that
14  you wrote the original software. If you use this software in a product,
15  an acknowledgment in the product documentation would be appreciated but is
16  not required.
17 
18  2. Altered source versions must be plainly marked as such, and must not be
19  misrepresented as being the original software.
20 
21  3. This notice may not be removed or altered from any source distribution.
22 */
23 #ifndef OIS_MacKeyboard_H
24 #define OIS_MacKeyboard_H
25 
26 #include "OISKeyboard.h"
27 #include "mac/MacHelpers.h"
28 #include "mac/MacPrereqs.h"
29 
30 #include <Carbon/Carbon.h>
31 
32 namespace OIS
33 {
34 
35  class MacKeyboard : public Keyboard
36  {
37  public:
38  MacKeyboard( InputManager* creator, bool buffered, bool repeat );
39  virtual ~MacKeyboard();
40 
41  // Sets buffered mode
42  virtual void setBuffered( bool buffered );
43 
44  // unbuffered keydown check
45  virtual bool isKeyDown( KeyCode key ) const;
46 
47  // This will send listener events if buffered is on.
48  // Note that in the mac implementation, unbuffered input is
49  // automatically updated without calling this.
50  virtual void capture();
51 
52  // Copies the current key buffer
53  virtual void copyKeyStates( char keys[256] ) const;
54 
55  // Returns a description of the given key
56  virtual std::string& getAsString( KeyCode key );
57 
58  virtual Interface* queryInterface( Interface::IType type ) { return 0; }
59 
60 
61  // Public but reserved for internal use:
62  virtual void _initialize();
63  void _keyDownCallback( EventRef theEvent );
64  void _keyUpCallback( EventRef theEvent );
65  void _modChangeCallback( EventRef theEvent );
66 
67 
68  protected:
69  // just to get this out of the way
70  void populateKeyConversion();
71 
72  // updates the keybuffer and optionally the eventStack
73  void injectEvent(KeyCode kc, unsigned int time, MacEventType type, unsigned int txt = 0 );
74 
75  typedef std::map<UInt32, KeyCode> VirtualtoOIS_KeyMap;
76  VirtualtoOIS_KeyMap keyConversion;
77 
79 
80  char KeyBuffer[256];
82 
83 
84  // "universal procedure pointers" - required reference for callbacks
85  EventHandlerUPP keyDownUPP;
86  EventHandlerUPP keyUpUPP;
87  EventHandlerUPP keyModUPP;
88 
89  // so we can delete the handlers on destruction
90  EventHandlerRef keyDownEventRef;
91  EventHandlerRef keyUpEventRef;
92  EventHandlerRef keyModEventRef;
93 
94  // buffered events, fifo stack
95  typedef std::list<MacKeyStackEvent> eventStack;
96  eventStack pendingEvents;
97 
98  bool useRepeat;
99 
100  };
101 }
102 #endif
EventHandlerUPP keyUpUPP
Definition: MacKeyboard.h:86
bool useRepeat
Definition: MacKeyboard.h:98
Definition: MacKeyboard.h:35
VirtualtoOIS_KeyMap keyConversion
Definition: MacKeyboard.h:76
virtual void _initialize()
Definition: MacKeyboard.cpp:92
MacKeyboard(InputManager *creator, bool buffered, bool repeat)
Definition: MacKeyboard.cpp:48
virtual bool isKeyDown(KeyCode key) const
Definition: MacKeyboard.cpp:132
An Object&#39;s interface is a way to gain write access to devices which support it.
Definition: OISInterface.h:34
void injectEvent(KeyCode kc, unsigned int time, MacEventType type, unsigned int txt=0)
Definition: MacKeyboard.cpp:304
::std::string string
Definition: gtest-port.h:756
EventHandlerRef keyDownEventRef
Definition: MacKeyboard.h:90
IType
Type of Interface.
Definition: OISInterface.h:40
void _modChangeCallback(EventRef theEvent)
Definition: MacKeyboard.cpp:244
EventHandlerRef keyUpEventRef
Definition: MacKeyboard.h:91
KeyCode
Keyboard scan codes.
Definition: OISKeyboard.h:31
EventHandlerUPP keyDownUPP
Definition: MacKeyboard.h:85
std::string getString
Definition: MacKeyboard.h:78
TypeWithSize< 4 >::UInt UInt32
Definition: gtest-port.h:1733
char KeyBuffer[256]
Definition: MacKeyboard.h:80
std::list< MacKeyStackEvent > eventStack
Definition: MacKeyboard.h:95
eventStack pendingEvents
Definition: MacKeyboard.h:96
virtual void capture()
Definition: MacKeyboard.cpp:139
virtual void setBuffered(bool buffered)
Definition: MacKeyboard.cpp:174
void _keyDownCallback(EventRef theEvent)
Definition: MacKeyboard.cpp:181
virtual ~MacKeyboard()
Definition: MacKeyboard.cpp:69
virtual bool buffered() const
Definition: OISObject.h:44
virtual Interface * queryInterface(Interface::IType type)
Definition: MacKeyboard.h:58
UInt32 prevModMask
Definition: MacKeyboard.h:81
void populateKeyConversion()
Definition: MacKeyboard.cpp:323
virtual void copyKeyStates(char keys[256]) const
Definition: MacKeyboard.cpp:315
virtual std::string & getAsString(KeyCode key)
Definition: MacKeyboard.cpp:166
Base Manager class.
Definition: OISInputManager.h:38
EventHandlerUPP keyModUPP
Definition: MacKeyboard.h:87
enum Mac_EventType MacEventType
Definition: MacHelpers.h:59
void _keyUpCallback(EventRef theEvent)
Definition: MacKeyboard.cpp:230
Definition: EventHelpers.h:31
std::map< UInt32, KeyCode > VirtualtoOIS_KeyMap
Definition: MacKeyboard.h:75
EventHandlerRef keyModEventRef
Definition: MacKeyboard.h:92
Type type() const
Definition: OISObject.h:38
Keyboard base class.
Definition: OISKeyboard.h:211