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.
Catch Mouse Events
Create an eventhandler class and inherit from irr::IEventReceiver. Override the OnEvent function and set the eventreceiver like this:
Also, check out the tutorials. It's all in there
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;
}
Never take advice from someone who likes to give advice, so take my advice and don't take it.