Skip to content

Commit 8151ae1

Browse files
committed
[src] Fix key event behavior to be able to hold key to move faster
1 parent a774162 commit 8151ae1

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/BeamAdapter/component/controller/BeamAdapterActionController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class BeamAdapterActionController : public sofa::component::controller::Mechanic
5959
/// Method to control the Beam using keyboard and save the actions in @sa d_actions
6060
void onKeyPressedEvent(core::objectmodel::KeypressedEvent* kev) override;
6161

62+
void onKeyReleasedEvent(core::objectmodel::KeyreleasedEvent* kev) override;
63+
6264
/// Unused metho for mouse event
6365
void onMouseEvent(core::objectmodel::MouseEvent* ev) override { SOFA_UNUSED(ev);}
6466

src/BeamAdapter/component/controller/BeamAdapterActionController.inl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <BeamAdapter/component/controller/BeamAdapterActionController.h>
2424
#include <sofa/core/objectmodel/MouseEvent.h>
2525
#include <sofa/core/objectmodel/KeypressedEvent.h>
26+
#include <sofa/core/objectmodel/KeyreleasedEvent.h>
2627

2728
namespace beamadapter
2829
{
@@ -69,10 +70,11 @@ void BeamAdapterActionController<DataTypes>::onKeyPressedEvent(core::objectmodel
6970
{
7071
if (!d_writeMode.getValue())
7172
return;
72-
73+
7374
/// Control keys for interventonal Radiology simulations:
7475
switch (kev->getKey())
7576
{
77+
7678
case 'E':
7779
m_currAction = BeamAdapterAction::NO_ACTION;
7880
m_exportActions = !m_exportActions;
@@ -108,6 +110,16 @@ void BeamAdapterActionController<DataTypes>::onKeyPressedEvent(core::objectmodel
108110
}
109111

110112

113+
template <class DataTypes>
114+
void BeamAdapterActionController<DataTypes>::onKeyReleasedEvent(core::objectmodel::KeyreleasedEvent* kev)
115+
{
116+
if (!d_writeMode.getValue())
117+
return;
118+
119+
m_currAction = BeamAdapterAction::NO_ACTION;
120+
}
121+
122+
111123
template <class DataTypes>
112124
void BeamAdapterActionController<DataTypes>::onBeginAnimationStep(const double /*dt*/)
113125
{
@@ -133,7 +145,6 @@ void BeamAdapterActionController<DataTypes>::onBeginAnimationStep(const double /
133145
}
134146

135147
m_lastAction = m_currAction;
136-
m_currAction = BeamAdapterAction::NO_ACTION;
137148
}
138149
else
139150
{

0 commit comments

Comments
 (0)