Detect mouse click?

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
fennec
Posts: 55
Joined: Fri Oct 10, 2008 7:23 am

Detect mouse click?

Post by fennec »

How do I detect if a mouse button is clicked?

I'm using a copy-pasted event receiver from the Movement example project.

I see that the keycodes list includes KEY_LBUTTON and KEY_RBUTTON, but they don't seem to be what I'm looking for. Nor does CursorControl have anything about buttons.

Thx a bunch.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Catch mouse events instead of keyboard ones. Also see SEvent.MouseInput
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Code: Select all

if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) do whatever;
knicholes
Posts: 14
Joined: Sat Aug 30, 2008 8:21 pm

What if you're using a separate file to handle your events?

Post by knicholes »

I'm trying to capture a mouse click and just have it change the text in the Hello World example. I can't put the code in the event handler because it doesn't know what the guienv object is, so I tried to put the code in main, but I don't know how to check for it from main--

while(device->run())
{
if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
{
guienv->addStaticText(L"Hello World! Event Recognition Complete!",
rect<int>(10,10,200,202), true);
}
...
}

This doesn't know what event is. I saw some guy do something with an array of keys, but I just don't get it. Please help!
aungsithu
Posts: 39
Joined: Thu Sep 04, 2008 2:14 am
Location: Singapore
Contact:

Post by aungsithu »

Check example4.
In class MyEventReceiver, OnEvent function, you can add another if statement to check whether the event is an EET_MOUSE_INPUT_EVENT.
Aung Sithu
*** Check out my latest book, Beginner's guide to Irrlicht 3D engine: http://bit.ly/rSnm4O
Company: http://rivaledge.sg
knicholes
Posts: 14
Joined: Sat Aug 30, 2008 8:21 pm

What if my handler is in a different file?

Post by knicholes »

In example 4, it shows how to handle the event by modifying the OnEvent() function that is in the SAME FILE as the main() function. It just modifies "node"'s position. If the OnEvent overridden call is in a different file, it won't know what "node" is. I'm wondering how you could accomplish this with two files, with the handler functions being separate from the main function.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Re: What if you're using a separate file to handle your even

Post by JP »

knicholes wrote: while(device->run())
{
if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
{
guienv->addStaticText(L"Hello World! Event Recognition Complete!",
rect<int>(10,10,200,202), true);
}
...
}
this is a really bad thing to do and shows you don't know how to code yet, i would suggest learning C++ first before jumping into 3D graphics... I don't mean to offend you, it's for the best!
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply