Duplicated mouse events?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Clash
Posts: 80
Joined: Thu Apr 19, 2007 4:20 pm

Duplicated mouse events?

Post by Clash »

Hello!
Just updated my code to irrLicht 1.4beta, but now I'm getting this weird problem where I get duplicated mouse events (not sure about the others events, I think they are normal)

I thought it was my code, but I just tested with the example 4

Code: Select all

class MyEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(const SEvent& event)
	{
		/*
		If the key 'W' or 'S' was left up, we get the position of the scene node,
		and modify the Y coordinate a little bit. So if you press 'W', the node
		moves up, and if you press 'S' it moves down.
		*/

		if (node != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT&&
			!event.KeyInput.PressedDown)
		{
			switch(event.KeyInput.Key)
			{
			case KEY_KEY_W:
			case KEY_KEY_S:
				{
					core::vector3df v = node->getPosition();
					v.Y += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;
					node->setPosition(v);
				}
				return true;
			}
		}

		if (event.EventType == irr::EET_MOUSE_INPUT_EVENT)
        {
            switch(event.MouseInput.Event)
            {
                case EMIE_LMOUSE_PRESSED_DOWN:
                {
                    std::cout << "pressed";
                }
            }
        }

		return false;
	}
};
As soon as I press the left mouse button, it prints pressed twice, "pressedpressed"

Any idea guys? The rest of the code is exactly as example 4

Thanks[/code]
jef
Posts: 18
Joined: Sat Nov 13, 2004 10:10 pm

Post by jef »

I think you should return true in "case EMIE_LMOUSE_PRESSED_DOWN".
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

This was a bug that is now fixed in SVN, the final 1.4 release won't have this problem :)

The problem was, the user receiver gets mouse input before the GUI, so if it isn't absorbed by the user then it is passed to the GUI. If the GUI doesn't catch the mouse event then it is passed back to the user receiver - causing two mouse events.

You can view the change to CGUIEnvironment.cpp here
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Clash
Posts: 80
Joined: Thu Apr 19, 2007 4:20 pm

Post by Clash »

Thanks bitplane
Post Reply