Hi everyone!
I have some buttons in my irrlicht application. Of course, when I hit SPACE or RETURN key, they are pressed, but I want to control them only by mouse. How can I disable these button events in the simpliest way? I've read that it can be done by capturing them in MyEventReceiver class. If so, what should I do first?
Disable keyboard events in buttons
-
- Posts: 7
- Joined: Thu Jul 02, 2015 10:13 pm
- Location: Wrocław, Poland
-
- Competition winner
- Posts: 688
- Joined: Mon Sep 10, 2012 8:51 am
Re: Disable keyboard events in buttons
There are actually two ways of doing this:
1) Create a class that inherits IEventReceiver and use the method IrrlichtDevice::setEventReceiver(IEventReceiver*) to control what happens when the button is pressed. You must then implement (in your class) the bool returning method OnEvent(const SEvent& event). Here, keyboard actions can be captured prior to being sent to buttons. This may take fiddling, depending on how you want everything else to respond. For example if you want other GUI events to respond to the space bar (such as text boxes), you'll have to check which GUI element is the focus using the method IGUIEnvironment::getFocus() inside your OnEvent function. If it's a button you don't want pressed, you return "true" from the OnEvent() method. If it's something else, you return false.
2) Create a GUI element that you add on top (as a child GUI element) of your buttons. Someone does this in one of the tutorials, though I forget which one. It still involves implementing OnEvent(), but in this case, you're using the function to only check for keyboard events (and not other things), and if the event is something else, you pass it back to the parent (which is the button, in this case).
In either case, I recommend looking at the file SEvent so you can get an idea of what events Irrlicht can handle and how they are stored.
Usually OnEvent is structured something like this:
1) Create a class that inherits IEventReceiver and use the method IrrlichtDevice::setEventReceiver(IEventReceiver*) to control what happens when the button is pressed. You must then implement (in your class) the bool returning method OnEvent(const SEvent& event). Here, keyboard actions can be captured prior to being sent to buttons. This may take fiddling, depending on how you want everything else to respond. For example if you want other GUI events to respond to the space bar (such as text boxes), you'll have to check which GUI element is the focus using the method IGUIEnvironment::getFocus() inside your OnEvent function. If it's a button you don't want pressed, you return "true" from the OnEvent() method. If it's something else, you return false.
2) Create a GUI element that you add on top (as a child GUI element) of your buttons. Someone does this in one of the tutorials, though I forget which one. It still involves implementing OnEvent(), but in this case, you're using the function to only check for keyboard events (and not other things), and if the event is something else, you pass it back to the parent (which is the button, in this case).
In either case, I recommend looking at the file SEvent so you can get an idea of what events Irrlicht can handle and how they are stored.
Usually OnEvent is structured something like this:
Code: Select all
switch( event.EventType )
{
case EET_GUI_EVENT:
switch( event.GUIEvent.EventType )
{
case EGET_BUTTON_PRESSED:
// Do something related to button pressing
break;
default: break;
}
break;
//... keyboard events, mouse events, etc.
// ...
default: break;
}
return false;
-
- Posts: 7
- Joined: Thu Jul 02, 2015 10:13 pm
- Location: Wrocław, Poland
Re: Disable keyboard events in buttons
OK, I'll check these ways.
Thanks
Thanks