opensurgsim
KeyBehavior.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013-2016, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_BLOCKS_KEYBEHAVIOR_H
17 #define SURGSIM_BLOCKS_KEYBEHAVIOR_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "SurgSim/Framework/Behavior.h"
23 
24 namespace SurgSim
25 {
26 namespace Input
27 {
28 class InputComponent;
29 }
30 
31 namespace Blocks
32 {
33 
37 {
38 public:
40  explicit KeyBehavior(const std::string& name);
41 
43  ~KeyBehavior();
44 
45  void update(double dt) override;
46  bool doInitialize() override;
47  bool doWakeUp() override;
48 
51  void setInputComponent(std::shared_ptr<Framework::Component> inputComponent);
52 
55  std::shared_ptr<Input::InputComponent> getInputComponent() const;
56 
61  static bool registerKey(int keycode, const std::string& description);
62 
66  static bool unregisterKey(int keycode);
67 
69  static void logMap();
70 
73  static void clearKeyMap();
74 
75 protected:
78  virtual void onKeyDown(int key) = 0;
79 
82  virtual void onKeyUp(int key) = 0;
83 
85  std::shared_ptr<Input::InputComponent> m_inputComponent;
86 
88  int m_lastKey;
89 
92  static boost::mutex m_keyMapMutex;
93  static std::unordered_map<int, std::string> m_keyMap;
95 };
96 
97 }; // namespace Blocks
98 }; // namespace SurgSim
99 
100 #endif
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
int m_lastKey
Keep track if the key was pressed the last time around.
Definition: KeyBehavior.h:88
std::shared_ptr< Input::InputComponent > m_inputComponent
Input component needs to provide key.
Definition: KeyBehavior.h:85
Behaviors perform actions.
Definition: Behavior.h:40
Behavior to abstract the functionality of keyboard driven behaviors, can be programmed to react to a ...
Definition: KeyBehavior.h:36
static boost::mutex m_keyMapMutex
Definition: KeyBehavior.h:92