KeyBehavior.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013-2016, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_BLOCKS_KEYBEHAVIOR_H
#define SURGSIM_BLOCKS_KEYBEHAVIOR_H
#include <memory>
#include <string>
#include "SurgSim/Framework/Behavior.h"
namespace SurgSim
{
namespace Input
{
class InputComponent;
}
namespace Blocks
{
class KeyBehavior : public Framework::Behavior
{
public:
explicit KeyBehavior(const std::string& name);
~KeyBehavior();
void update(double dt) override;
bool doInitialize() override;
bool doWakeUp() override;
void setInputComponent(std::shared_ptr<Framework::Component> inputComponent);
std::shared_ptr<Input::InputComponent> getInputComponent() const;
static bool registerKey(int keycode, const std::string& description);
static bool unregisterKey(int keycode);
static void logMap();
protected:
virtual void onKeyDown(int key) = 0;
virtual void onKeyUp(int key) = 0;
std::shared_ptr<Input::InputComponent> m_inputComponent;
int m_lastKey;
static boost::mutex m_keyMapMutex;
static std::unordered_map<int, std::string> m_keyMap;
};
}; // namespace Blocks
}; // namespace SurgSim
#endif
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Blocks::KeyBehavior::m_keyMap
static std::unordered_map< int, std::string > m_keyMap
Definition: KeyBehavior.h:89
Behavior.h
SurgSim::Blocks::KeyBehavior::m_lastKey
int m_lastKey
Keep track if the key was pressed the last time around.
Definition: KeyBehavior.h:84
SurgSim::Blocks::KeyBehavior::m_inputComponent
std::shared_ptr< Input::InputComponent > m_inputComponent
Input component needs to provide key.
Definition: KeyBehavior.h:81
SurgSim::Framework::Behavior
Behaviors perform actions.
Definition: Behavior.h:40
SurgSim::Blocks::KeyBehavior
Behavior to abstract the functionality of keyboard driven behaviors, can be programmed to react to a ...
Definition: KeyBehavior.h:36
SurgSim::Blocks::KeyBehavior::m_keyMapMutex
static boost::mutex m_keyMapMutex
Definition: KeyBehavior.h:88