iMSTK
Interactive Medical Simulation Toolkit
imstkKeyboardDeviceClient.h
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 #pragma once
8 
9 #include "imstkDeviceClient.h"
10 
11 #include <unordered_map>
12 
13 namespace imstk
14 {
15 using KeyStateType = int;
16 #define KEY_RELEASE 0
17 #define KEY_PRESS 1
18 
24 class KeyEvent : public Event
25 {
26 public:
27  KeyEvent(const std::string type, const char key, const KeyStateType keyPressType) : Event(type), m_keyPressType(keyPressType), m_key(key) { }
28  ~KeyEvent() override = default;
29 
30 public:
31  KeyStateType m_keyPressType;
32  const char m_key = -1;
33 };
34 
41 {
42 protected:
46  KeyboardDeviceClient() : DeviceClient("KeyboardDevice", "") { }
47 
51  static std::shared_ptr<KeyboardDeviceClient> New();
52 
53 public:
54  ~KeyboardDeviceClient() override = default;
55 
56  // Only these classes may provide this object
57  friend class VTKInteractorStyle;
58  friend class ConsoleModule;
59 
60 public:
61  // *INDENT-OFF*
65  SIGNAL(KeyboardDeviceClient, keyPress);
66 
70  SIGNAL(KeyboardDeviceClient, keyRelease);
71  // *INDENT-ON*
72 
73 public:
74  const std::unordered_map<int, KeyStateType>& getKeyState() const { return m_buttons; }
75 
76 protected:
80  void emitKeyDown(char key);
81 
85  void emitKeyUp(char key);
86 
90  bool isKeyDown(const char key) const;
91 };
92 } // namespace imstk
The device client&#39;s represents the device and provides an interface to acquire data from a device...
Base class for events which contain a type, priority, and data priority defaults to 0 and uses a grea...
Compound Geometry.
This class provides the keyboard state it also posts events.
Provides the information of a key event (press, release, & which key)
The console thread can run separately or in sync to provide keyboard events from the console they sho...
Interactor styles forward their controls to imstk objects.