Problem with 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
AndrewT
Posts: 11
Joined: Mon Jan 21, 2008 4:00 pm
Location: Michigan, USA

Problem with mouse events

Post by AndrewT »

I'm trying to figure out how I can get mouse presses; that is, I want a function to return true only when the mouse is initially pressed, after that it will return false until the next time I click the mouse. Here's my event receiver code:

Code: Select all

class MyEventReceiver : public IEventReceiver
{
public:

	MyEventReceiver( )
	{
		MouseLeftClicked = 0;
		MouseLeftHeld = 0;
		return;
	}
	bool OnEvent( const SEvent &event )
	{
		if ( event.EventType == EET_MOUSE_INPUT_EVENT )
		{
			if ( event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN )
			{
				if ( MouseLeftHeld == 0 )
				{
					MouseLeftClicked = 1;
				}
				else
				{
					MouseLeftClicked = 0;
				}
				MouseLeftHeld = 1;
			}
			if ( event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP )
			{
				MouseLeftClicked = 0;
				MouseLeftHeld = 0;
                        }
		}
		return false;
	}
	bool GetMouseLeftClicked( )
	{
		return MouseLeftClicked;
	}
	bool GetMouseLeftHeld( )
	{
		return MouseLeftHeld;
        }
private:

	bool MouseLeftClicked;
	bool MouseLeftHeld;

};
And it's not working. GetMouseLeftClicked( ) is returning true as long as the left button is being held, but it should only be returning true one time when the mouse is pressed. Any ideas what's going wrong? I know I'm probably missing something really stupid and obvious.
geronika2004
Posts: 11
Joined: Mon Jan 22, 2007 5:42 pm
Location: Tbilisi, Georgia, Eastern Europe
Contact:

Post by geronika2004 »

event

Code: Select all

event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN 
is generated only one time when you click left button
MouseLeftHeld becomes 1 and MouseLeftClicked becomes also 1. The execution of event stops, so this code will never be checked:

Code: Select all

            else 
            { 
               MouseLeftClicked = 0; 
            } 
AndrewT
Posts: 11
Joined: Mon Jan 21, 2008 4:00 pm
Location: Michigan, USA

Post by AndrewT »

Ahhhh, ok. Thanks.

Is EMIE_LMOUSE_LEFT_UP the same way? Will it only be generated once when the mouse button is released, or is generated constantly as long as the mouse button is up?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

The mouse button events only come when the state of the mouse buttons have changed. This is consistent for all mouse button events.

Travis
AndrewT
Posts: 11
Joined: Mon Jan 21, 2008 4:00 pm
Location: Michigan, USA

Post by AndrewT »

K, thanks.
Post Reply