ros-visualization/rviz

I want to get the key release event in rviz::Tool class

Closed this issue · 14 comments

I want to get the key release event in rviz::Tool class

but the function processKeyEvent can only get pressed key event.

Is there any way to get released key event?

Not yet. You would need to augment the class and build from source. Is there a special reason you need this event?

I've rewritten the ProcessKeyEvent function, but it can only receive keyboard press events, not keyboard release events

so,Why is this KeyRelease not responding

Because RenderPanel is only overriding keyPressEvent() not keyReleaseEvent():

void keyPressEvent(QKeyEvent* event) override;

Again my question: Why do you need the release event? What do you want to achieve eventually?

int OverlayPickerTool::processKeyEvent(QKeyEvent* event, rviz::RenderPanel* panel)
{
if (event->type() == QEvent::KeyPress && event->key() == 16777248) { // sift
shift_pressing_ = true;
}
else if (event->type() == QEvent::KeyRelease && event->key() == 16777248) {
shift_pressing_ = false;
}
return 0;
}
I want to implement a mechanism in my custom rviz plugin that resets the condition when the SHIFT key is pressed to perform an event

If I want this condition to be responsive, what do I do:
else if (event->type() == QEvent::KeyRelease && event->key() == 16777248) {
shift_pressing_ = false;
}

Indeed, if you need to receive KeyRelease events, you need to modify rviz itself as suggested in #1770 (comment)

But how do I modify rviz?
Modify render_panel.h?Do I put a KeyReleaseEvent function in there?

Yes, both in render_panel.h and render_panel.cpp. You need to include rviz in your catkin workspace of course.

I've changed render_panel.h in a file on my own virtual machine,and I don't have this render_panel.cpp,But processKeyEvent doesn't work

I've changed render_panel.h in a file on my own virtual machine,and I don't have this render_panel.cpp

Obviously, you need to clone the rviz repo (this one) into your catkin workspace. Just changing render_panel.h in /opt/ros doesn't help at all.

omg,Thank you very much for your help.