INPUT_EVENT no longer receives a key input. All the code is happening so fast within the OnEvent method.
I just wondered when to check a value within the Event system?
No, I probably haven't thought it through as much as I should have, but it's good to ask a question from time to time.
..
Code: Select all
class MyEventReceiver : public IEventReceiver
{
public:
// give input a gui quit button
MyEventReceiver(Context & c) : context(c) { }
// This is the one method that we have to implement
virtual bool OnEvent(const SEvent& event)
{
// Remember whether each key is down or up
if (event.EventType == irr::EET_KEY_INPUT_EVENT)
{
KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
// check here
// D0 U1 (before event)
// D1 U1 (line event.KeyInput.PressedDown
// D1 U0 (line !event.KeyInput.PressedDown
// D0 U0 (line event.KeyInput.PressedDown
// D0 U1 (line !event.KeyInput.PressedDown
if(KeyIsDown[event.KeyInput.Key] == 0 && KeyIsUp[event.KeyInput.Key] == 0)
ToggleView();
KeyIsUp[event.KeyInput.Key] = !event.KeyInput.PressedDown;
// EVERY key released?
//KeyIsReleased[event.KeyInput.Key] = 0;
}
if(event.EventType == irr::EET_MOUSE_INPUT_EVENT)
{
RightMouse = event.MouseInput.isRightPressed();
mouse_xy.X = event.MouseInput.X;
mouse_xy.Y = event.MouseInput.Y;
}
if(event.MouseInput.Event == EMOUSE_INPUT_EVENT::EMIE_RMOUSE_LEFT_UP)
RightMouse = false;
return false;
}
// This is used to check whether a key is being held down
virtual bool IsKeyDown(EKEY_CODE keyCode) const
{
return KeyIsDown[keyCode];
}
virtual bool IsKeyUp(EKEY_CODE keyCode) const
{
return KeyIsUp[keyCode];
}
virtual bool IsRightClick() const
{
return RightMouse;
}
virtual bool IsQuit()
{
return context.quit_app;
}
virtual core::position2d<s32> getXY()
{
return mouse_xy;
}
virtual void ToggleView()
{
context.viewing_cam = !context.viewing_cam;
std::cout << "?: " << context.viewing_cam;
}
virtual bool getView()
{
return context.viewing_cam;
}
// init
MyEventReceiver()
{
for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
KeyIsDown[i] = false;
for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
KeyIsUp[i] = true;
}
private:
// We use this array to store the current state of each key
bool KeyIsDown[KEY_KEY_CODES_COUNT];
bool KeyIsUp[KEY_KEY_CODES_COUNT];
bool RightMouse = false;
int event_tot = 0;
core::position2d<s32> mouse_xy = {0,0};
Context context;
};
The calling code is here, but so far it is set to IsKeyDown, which isn't what I want. It does work (sort of) but only when the key is down. I'd like it to trigger when the key is up.
Code: Select all
if(receiver.IsKeyDown(irr::KEY_KEY_1))
{
if(receiver.getView())
{
smgr->setActiveCamera(no_camera);
fps_mention->setText(L"NO FPS");
}
else
{
smgr->setActiveCamera(camera);
fps_mention->setText(L"FPS");
}
}