I'm using Irrlicht to make a simple 2D game.
Using IEventListener, I'm dealing with key input event so that 2D character can move.
Also, I fixed FPS as 30 FPS using GetTickCount() function, so I can get 30 inputs per second (one input for one frame).
However, I have a problem that irrlicht gets user's input twice event if i clicked a key just once, very carefully.
It happens for every key input; not just arrow key, but also other keys like space bar, etc.
Why is this situation happening? I really don't know with my knowledge.
Why Key input event occurs twice?
Why Key input event occurs twice?
From Seoul, South Korea
Re: Why Key input event occurs twice?
Once on pressing down and once on release? Or do you mean the key-repeat maybe? Otherwise hard to say without example.
Here's the code I often use for testing key-event behavior, maybe it helps:
Here's the code I often use for testing key-event behavior, maybe it helps:
Code: Select all
#include <irrlicht.h>
#include <iostream>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif
class MyEventReceiver : public IEventReceiver
{
bool OnEvent( const SEvent &event )
{
if (event.EventType == EET_KEY_INPUT_EVENT)
{
if( event.KeyInput.PressedDown )
{
std::cout << "PressedDown:" << event.KeyInput.Key << std::endl;
}
else if( !event.KeyInput.PressedDown )
{
std::cout << "!PressedDown:" << event.KeyInput.Key << std::endl;
}
}
return false;
}
};
int main()
{
video::E_DRIVER_TYPE driverType = video::EDT_OPENGL;
IrrlichtDevice * device = createDevice(driverType, core::dimension2d<u32>(640, 480));
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
MyEventReceiver receiver;
device->setEventReceiver(&receiver);
while(device->run() && driver)
{
if (device->isWindowActive())
{
// device->sleep(1000);
//
}
}
device->drop();
return 0;
}
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Why Key input event occurs twice?
Oh I solved it. My problem was that it checks user's key input and move character in OnEvent Function.
After I moved the MoveCharacter() function in while(dev->run()), it gets exactly one input!
Thank you
After I moved the MoveCharacter() function in while(dev->run()), it gets exactly one input!
Thank you
From Seoul, South Korea