You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Well i have this code that is suposed to execute only ONCE when a button is held down, but on linux (i guess?) it likes to switch between pressed and not pressed so i haven't a clue right now how i'm suposed to know if someone is pressing a button constantly quickly or if they have it held down.
I'd think the key input alternates between pressed and not pressed when you hold the key due to the keyboard auto-repeat. If you open up an editor and hold down the W key, you get one W, a small delay, then a continuous stream of Ws. The continuous stream of Ws happens because the driver is simulating key presses by reporting the key is pressed then released repeatedly. This is reasonable behavior.
One thing you might try is to set all of the flags in one area of code, and then do something with those settings somewhere else...
yes its not so bad that it continuely presses it, whats bad is that irrlicht registers it has being released too, which is not happening. it gives a w presseddown == 1 followed by a w presseddown == 0 (repeatedly), even though the button was constantly held down. And because of this i have no way of knowing if its actauly being held down or if they actauly just pressed the button normaly.
The ultimate goal is to have a function called when it is pressed down, followed by another function being called after it is let up (these functions in my case being player_ship->send_exhaust(0); and player_ship->send_exhaust(1);)
It is not a bug that irrlicht sends a key up message. The OS is reporting a key up, and irrlicht reports that.
You really need to have a look at what I've done above. If you need to know the previous state and the new state, then you should keep two copies of key state and swap them.
I'm not running linux, so I can't test this, but it should work.
I guess the real issue is that there is a difference in behavior between windows and linux, and that should probably be fixed. Problems like that cause big headaches after a project is finished and you are trying to port to a platform that should just work right out of the box.
Thanks alot for the help, but i guess i'll have to move over to SDL for input control whenever i get to the point where this problem holds alittle more weight then the list of other things i need to get done. Then switch back over when the problem is fixed. If anyone knows the solution to this problem with the current release of irrlicht please tell me =) Otherwise i will wait until the next release...
I face the same problem. Irrlicht lacks setKeyAutorepeat (bool state) function.
vitek's suggesion is nothing useful, because when i hold, say, W key, i get key presses / releases constantly.
I was thinking of not counting in those presses / releases that occur within small interval, that's what happens when key autorepeats. But if user indeed pressed / released key within short delay, the key press / release won't get to target...
Any ideas to overcome it?
Thanks.
//keyboard input
if( event.EventType == EET_KEY_INPUT_EVENT )
{
//check if the key is being pressed or released
if( event.KeyInput.PressedDown )
{
//set pressed down state
m_keys[ event.KeyInput.Key ] = true;
}
else
{
//set released state
m_keys[ event.KeyInput.Key ] = false;
}
//event handled
return true;
}
an excerpt of my input manager code. i hope this is helpful. perhaps the issue here is that you are acting on key events to run game code... you should really be just modifying a state and then querying that state elsewhere for updating your game (so intermediate changes wont run anything prematurely). but i dont have linux so i can only hypothesize.
Last edited by xskinyx on Sat Feb 03, 2007 4:37 am, edited 2 times in total.