Hi Renan,

switch(ea.getEventType())
{
     case(osgGA::GUIEventHandler::DRAG)
     {
// Here I'd like to check if a key was pressed -- how can I do it?
     }
}

You would need to handle the case where a key is pressed and released, and keep some state in your event handler yourself to know which keys are pressed at the time that your mouse drag event is received. So something like:

  switch(ea.getEventType())
  {
       case(osgGA::GUIEventHandler::KEYDOWN)
       {
           // Store ea.getKey() in a vector or something like that
           _keysPressed.push_back(ea.getKey());

           return true;
       }
       case(osgGA::GUIEventHandler::KEYUP)
       {
           // Remove ea.getKey() from the vector or something like that
           std::vector<int>::iterator it =
               std::find(_keysPressed.begin(), _keysPressed.end(),
                   ea.getKey());

           if (it != _keysPressed.end())    // found
               _keysPressed.erase(it);

           return true;
       }
       case(osgGA::GUIEventHandler::DRAG)
       {
           // Assuming you want to check that the 'a' key is pressed
           std::vector<int>::iterator it =
               std::find(_keysPressed.begin(), _keysPressed.end(),
                   'a');

           if (it != _keysPressed.end())    // found --> it was pressed
           {
               // Do what you want
           }
       }
  }

(note: you need to #include <algorithm> to use std::find().)

Hope this helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay    [EMAIL PROTECTED]
                               http://www.cm-labs.com/
                        http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to