iMSTK
Interactive Medical Simulation Toolkit
imstkKeyboardControl.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 "imstkKeyboardControl.h"
8 #include "imstkKeyboardDeviceClient.h"
9 
10 namespace imstk
11 {
12 void
13 KeyboardControl::setDevice(std::shared_ptr<DeviceClient> device)
14 {
15  // Remove old observer if it exists
16  if (m_deviceClient != nullptr)
17  {
18  disconnect(m_deviceClient, shared_from_this(), &KeyboardDeviceClient::keyPress);
19  disconnect(m_deviceClient, shared_from_this(), &KeyboardDeviceClient::keyRelease);
20  }
21 
22  // Set the new device
23  DeviceControl::setDevice(device);
24 
25  // Subscribe to the device clients events
26  connect(device, &KeyboardDeviceClient::keyPress,
27  shared_from_this(), &KeyboardControl::keyPressEvent);
28  connect(device, &KeyboardDeviceClient::keyRelease,
29  shared_from_this(), &KeyboardControl::keyReleaseEvent);
30 }
31 
32 void
34 {
35  OnKeyPress(keyPressEvent->m_key);
36 }
37 
38 void
40 {
41  OnKeyRelease(keyPressEvent->m_key);
42 }
43 } // namespace imstk
friend void disconnect(std::shared_ptr< EventObject >, std::shared_ptr< EventObject >, std::string(*)())
Remove an observer from the sender.
Compound Geometry.
virtual void keyReleaseEvent(KeyEvent *e)
Recieves key release event.
Provides the information of a key event (press, release, & which key)
virtual void keyPressEvent(KeyEvent *e)
Recieves key press event.