游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1943|回复: 1

为什么监听器不能捕获鼠标事件呢?

[复制链接]

53

主题

98

帖子

101

积分

注册会员

Rank: 2

积分
101
发表于 2008-1-11 09:08:00 | 显示全部楼层 |阅读模式

我定义了一个帧监听器类,它的构造函数如下:
TestListener::TestListener(RenderWindow* pRenderWindow)
{
OIS:aramList pl;
size_t windowHnd = 0;
std:stringstream windowHndStr;
pRenderWindow->getCustomAttribute("WINDOW", &windowHnd);
windowHndStr << windowHnd;
pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
InputManager* mInputManager = OIS::InputManager::createInputSystem( pl );

Mouse* mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject( OIS::OISMouse, true ));
WindowEventUtilities::addWindowEventListener(pRenderWindow, this);
mMouse->setBuffered(false);

mMouse->setEventCallback(this);

}

现在我程序中创建了一个帧监听器,并注册到在根中:
TestListener* pListener = new TestListener(pWindow);
pRoot->addFrameListener(pListener);
可为什么该监听器不能捕获鼠标事件呢?

奇怪的是为什么
bool TestListener::frameStarted(const Ogre::FrameEvent& evt)
{
return true;
}
函数会自动调用?
而当按下鼠标时却不会响应
bool TestListener::mousePressed( const MouseEvent &arg, MouseButtonID id )
{

return true;
}
函数?

0

主题

1

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2008-4-7 12:05:00 | 显示全部楼层

Re:为什么监听器不能捕获鼠标事件呢?

看代码:
void Win32Keyboard::_readBuffered()
{
  DIDEVICEOBJECTDATA diBuff[KEYBOARD_DX_BUFFERSIZE];
    DWORD entries = KEYBOARD_DX_BUFFERSIZE;  
   mKeyboard->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), diBuff, &entries, 0 );
    //Update keyboard and modifier states.. And, if listener, fire events
    for(unsignedinti = 0; i < entries; ++i )
    {
       KeyCode kc = (KeyCode)diBuff[ i ].dwOfs;
                     if( diBuff[ i ].dwData & 0x80 )
       {
          if( listener )
            istener->keyPressed( KeyEvent( this,kc,_translateText(kc) ) );
       }
       else
       {
           //Fire off event
           if( listener )
            listener->keyReleased( KeyEvent( this, kc, 0 ) );
       }
    }
}

void Win32Keyboard::_read()
{
  mKeyboard->GetDeviceState( sizeof(KeyBuffer), &KeyBuffer );  
}

貌似只有在缓冲模式下才能使用事件监听。
尝试把mMouse->setBuffered(false);改mMouse->setBuffered(true);
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-22 22:59

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表