Hi,
I want to get events from the keyboard. To do this I created a class by
deriving "osgGA::GUIEventHandler" and implemented "hanlder" method.
But my program is not catching the events. Here is my code
Code:
class KeyboardEventHandler : public osgGA::GUIEventHandler
{
bool isImageCaptured;
public:
KeyboardEventHandler(): osgGA::GUIEventHandler()
{
isImageCaptured=false;
}
virtual bool handle(const osgGA::GUIEventAdapter&
ea,osgGA::GUIActionAdapter&);
bool getImageCapFlag()
{
return isImageCaptured;
}
};
bool KeyboardEventHandler::handle(const osgGA::GUIEventAdapter&
ea,osgGA::GUIActionAdapter& aa)
{
std::cout<<"In Event Handler"<<std::endl;
switch(ea.getEventType())
{
case(osgGA::GUIEventAdapter::KEYDOWN):
{
std::cout<<"Event handerler "<<std::endl;
switch(ea.getKey())
{
case 'i':
std::cout << "I Pressed " << std::endl;
isImageCaptured=false;
return false;
break;
default:
return false;
}
}
default:
return false;
}
}
In the above code I am getting "In Event Handler" message but not getting "I
Pressed".
I also implemented the following code to take a screen capture. If I remove
this code than key board events are working
Code:
HMONITOR monitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
MONITORINFO info;
info.cbSize = sizeof(MONITORINFO);
GetMonitorInfo(monitor, &info);
int XRes = info.rcMonitor.right - info.rcMonitor.left;
int YRes = info.rcMonitor.bottom - info.rcMonitor.top;
traits = new osg::GraphicsContext::Traits;
traits->target = osg::Camera::FRAME_BUFFER_OBJECT;
traits->x =0;
traits->y =0;
traits->width = XRes;
traits->height = YRes;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = 0;
traits->pbuffer = false;
gContext= osg::GraphicsContext::createGraphicsContext(traits.get());
viewer->getCamera()->setGraphicsContext(gContext);
gCamera = viewer->getCamera();
gCamera->setViewport(new osg::Viewport(0,0,XRes,YRes));
double fovy, aspectRatio, zNear, zFar;
gCamera->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear,
zFar);
fovy+=41.0;
gCamera->setProjectionMatrixAsPerspective(fovy, aspectRatio, zNear,
zFar);
viewer->setDataVariance(osg::Object::DYNAMIC);
viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
sCapImage = new osg::Image;
sCapImage->allocateImage(720, 576, 1, GL_RGB, GL_UNSIGNED_BYTE);
gCamera->attach(osg::Camera::COLOR_BUFFER, sCapImage);
I added "setAllowEventFocus(false)" for both gCamera and main camera. Even I am
not getting key board events
Can you please help me where am I doing wrong?
...
Thank you!
Cheers,
Koduri
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=48164#48164
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org