Catch 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
manik_sheeri
Posts: 53
Joined: Tue May 19, 2009 12:18 am

Catch Mouse Events

Post by manik_sheeri »

Hi,

I have an Irrlicht Application and I am required to catch Mouse Press events in my application to find out the (X,Y) coordinates of the Mouse Click on the screen.

Any idea how I can achieve this.

cheers.
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

Create an eventhandler class and inherit from irr::IEventReceiver. Override the OnEvent function and set the eventreceiver like this:

Code: Select all

device->setEventReceiver(PointerToMyEventHandlerClassInstance);

Code: Select all

bool CEventHandler::OnEvent(const irr::SEvent &e)
{
  switch (e.EventType)
  {
    case EET_KEY_INPUT_EVENT :
    {
      // save keydown in an array
      keyDown[e.KeyInput.Key] = e.KeyInput.PressedDown;

      if (e.KeyInput.PressedDown)
      {
        switch (e.KeyInput.Key)
        {
          case KEY_ESCAPE :
          {
            device->closeDevice();
          } break;

          case KEY_SPACE :
          {
            // do stuff
          } break;
        }
      }
    } break;

    case EET_MOUSE_INPUT_EVENT :
    {
      switch (e.MouseInput.Event)
      {
        case EMIE_LMOUSE_PRESSED_DOWN :
        {
          // left mouse clicked
          // do stuff here
          u32 mouseX = e.MouseInput.X;
          u32 mouseY = e.MouseInput.Y;
        } break;

        case EMIE_RMOUSE_PRESSED_DOWN :
        {
          // right mouse clicked
          // do stuff here
        } break;
      }
    } break;
  }

  return false;
}
Also, check out the tutorials. It's all in there :)
Never take advice from someone who likes to give advice, so take my advice and don't take it.
Post Reply