- This topic has 5 replies, 4 voices, and was last updated 8 years, 5 months ago by .
Viewing 6 posts - 1 through 6 (of 6 total)
Viewing 6 posts - 1 through 6 (of 6 total)
- You must be logged in to reply to this topic.
Home › Forum › SOFA › Programming with SOFA › [SOLVED] Keyboard events in SOFA
Hello,
I’m trying to use the event handler to change some parameters of my componentes when some key is pressed, but the handleEvent method is not receiving any keypressed event.
Here is my code
template<class DataTypes>
void LinearISOElasticityFEMAD<DataTypes>::handleEvent(sofa::core::objectmodel::Event *event)
{
// Key pressed event
sofa::core::objectmodel::KeypressedEvent *ev = dynamic_cast<sofa::core::objectmodel::KeypressedEvent*>(event);
std::cout << event->getClassName() << std::endl;
if(ev != NULL)
{
std::cout << "Keyboard event" << std::endl;
switch(ev->getKey())
{
// The key E is pressed
case 'e':
//Something should happened here
default:
break;
}
}
}
The problem is that I’m never entering in the if statement. The print output says that I’m receiving this events
AnimateBeginEvent
CollisionBeginEvent
CollisionEndEvent
IntegrateBeginEvent
Optimizer solver
IntegrateEndEvent
AnimateEndEvent
UpdateMappingEndEvent
MouseEventnt
Any idea to get keyboard events?
Hi jjcasmar,
Did you press the control key when you were trying to catch the letters?
Rosalie
uhhh, no… should I?
Hi jjcasmar,
In fact the keyboard events are emitted by the viewer, when Ctrl is pressed (or Cmd on macs).
So, the viewer must have the focus (just click on the viewport once to be sure) ans you must press Ctrl+
Bruno
Hi all,
Just to add a small detail, you need to set the variable “f_listening” to true. This variable is common to all BaseObject. If true, this variable will allow the call of the handleEvent function in your component.
Hope this helps.
Hugo
Hi JuanJo,
I think we answered your question about this point.
If you have any further questions or issues do not hesitate to create a new thread.
Best,
Hugo
WARNING
The forum has been moved to GitHub Discussions.
Old topics and replies are kept here as an archive.