|
bool KeyboardEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&)
{
int keyNum;
CString s ;
switch (ea.getEventType())
{
case(osgGA::GUIEventAdapter::KEYDOWN):
keyNum = ea.getKey();
switch(keyNum)
{
case 'm': keyNum = 'w';break;
case osgGA::GUIEventAdapter::KEY_Up: keyNum = 'w';break;
case osgGA::GUIEventAdapter::KEY_Down: keyNum = 's';break;
case osgGA::GUIEventAdapter::KEY_Left: keyNum = 'a';break;
case osgGA::GUIEventAdapter::KEY_Right: keyNum = 'd';break;
}
s.Format("%d",keyNum );
AfxMessageBox("keyNum is "+s);
if(keyNum>=0&&keyNum<256)keyDown[keyNum] = true;
break;
case(osgGA::GUIEventAdapter::KEYUP):
keyNum = ea.getKey();
if(keyNum>=0&&keyNum<256)keyDown[keyNum] = false;
break;
default:
break;
}
//return false to allow mouse manipulation
return false;
}
运行后,当按下上下左右这四个键的时候没有任何反应,按下其他键的时候就会弹出message对话框,输出keyNum,但是如果把messageBox添加到KEYUP下,就可以弹出对话框,请问是什么原因啊?我的程序什么地方有问题呢? |
|