iMSTK
Interactive Medical Simulation Toolkit
imstkKeyboardDeviceClient.cpp
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #include "imstkKeyboardDeviceClient.h"
8 
9 namespace imstk
10 {
11 std::shared_ptr<KeyboardDeviceClient>
13 {
14  return std::shared_ptr<KeyboardDeviceClient>(new KeyboardDeviceClient());
15 }
16 
17 void
19 {
20  const int prevKeyState = m_buttons[key];
21  m_buttons[key] = KEY_PRESS;
22  if (prevKeyState != KEY_PRESS)
23  {
24  this->postEvent(KeyEvent(KeyboardDeviceClient::keyPress(), key, KEY_PRESS));
25  }
26 }
27 
28 void
30 {
31  const int prevKeyState = m_buttons[key];
32  m_buttons[key] = KEY_RELEASE;
33  if (prevKeyState != KEY_RELEASE)
34  {
35  this->postEvent(KeyEvent(KeyboardDeviceClient::keyRelease(), key, KEY_RELEASE));
36  }
37 }
38 
39 bool
40 KeyboardDeviceClient::isKeyDown(const char key) const
41 {
42  if (m_buttons.find(key) != m_buttons.end())
43  {
44  return (m_buttons.at(key) == KEY_PRESS);
45  }
46  else
47  {
48  return false;
49  }
50 }
51 } // namespace imstk
bool isKeyDown(const char key) const
Returns true if key is currently down.
void emitKeyUp(char key)
Post a key release.
static std::shared_ptr< KeyboardDeviceClient > New()
Compound Geometry.
Provides the information of a key event (press, release, & which key)
void emitKeyDown(char key)
Post a key press.
void postEvent(const T &e)
Emits the event Direct observers will be immediately called, in sync Queued observers will receive th...