void MyViewer::handleMouseClick(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) { if (ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON) { // Do something on left mouse button click } else if (ea.getButton() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON) { // Do something on right mouse button click } } void MyViewer::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) { switch (ea.getEventType()) { case osgGA::GUIEventAdapter::PUSH: handleMouseClick(ea, aa); break; } }
void MyViewer::handleKeyboard(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) { if (ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN) { switch (ea.getKey()) { case 'a': // Do something when 'a' key is pressed break; case 'b': // Do something when 'b' key is pressed break; } } } void MyViewer::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) { switch (ea.getEventType()) { case osgGA::GUIEventAdapter::KEYDOWN: handleKeyboard(ea, aa); break; } }This code example checks for keyboard events and performs a different action based on which key was pressed. The package library for cpp osgGA is OpenSceneGraph.