Page 1 of 1

Multiple keys pressed

Posted: Tue Nov 03, 2009 12:42 pm
by raytaller
Hello,
I have a problem with key presses when several ( >= 3 ) keys are down. Depending on the combination, the third key press event is never received.

My code :

Code: Select all

if (event.EventType == EET_KEY_INPUT_EVENT)
{
    if (event.KeyInput.PressedDown) {
        // Not reached
    }
}
I assume it is because the system key event is called repeatedly, so there are too much events triggered.
Is there a better, portable way to manage key events so :
- they occur only when the state of the key is changing
- it is possible to press more than 2 or 3 keys in the same time

If not, would you recommend a simple and portable Input library that manages mouse, keyboard and gamepad ?

Posted: Tue Nov 03, 2009 2:29 pm
by CuteAlien
Irrlicht does not drop any key-events. So if the system generates them then you should also receive them. So either there is some other problem which can't be seen in your code here or it's a problem of your keyboard. To help on code-problems you have to paste more code. To check if it's your keyboard (and that's a rather common problem as many keyboards don't support sending keys for certain multiple keypresses) you can try pressing the same combinations for example in a texteditor. For example when you already hold down asd-keys then maybe the f-key will no longer react when pressed additionally (or other combinations - I don't know which do work and which don't).

Posted: Tue Nov 03, 2009 2:30 pm
by hybrid
No, this works in principle. But depending on your keyboard, certain combinations of keys are not possible at the same time. You could try with different keyboards, or switch to additional mouse/joypad events.

Posted: Tue Nov 03, 2009 9:59 pm
by Kalango
Yeah most of the times the problem is the keyboard or the keyboard drivers...
You should try keys with different axes or other solution if this is realy important.
Also joystick is a good input hardware to solve this kind of problems...

Posted: Wed Nov 04, 2009 12:33 pm
by raytaller
Thanks for your help !
Hmm... I have to check this but I'm pretty sure I was just moving with left and up, and shooting with space.
Up + left + space is not a so exotic combination.

Code: Select all

class CustomEventReceiver : public IEventReceiver
{	
virtual bool OnEvent(const SEvent & event)
{
	/// Keyboard ///
	if (event.EventType == EET_KEY_INPUT_EVENT)
	{
		::u8 code = (::u8)event.KeyInput.Key;
		
		// If state changed
		if(event.KeyInput.PressedDown != ks[code].down)
		{
			if(game->inputs_enabled())
				game->get_lua().call_function_scoped("input", "on_key_event", event.KeyInput.Key, event.KeyInput.PressedDown, event.KeyInput.Shift, event.KeyInput.Control);
		}
		
		// Update state
		if (event.KeyInput.PressedDown) {
			ks[ code ].down = true;
		}else{
			ks[ code ].down = false;
		}

	}
}
}
CustomEventReceiver g_custom_evt_receiver;
device->setEventReceiver(&g_custom_evt_receiver);

Posted: Thu Nov 05, 2009 1:08 am
by randomMesh
raytaller wrote:Up + left + space is not a so exotic combination.
There are many, many keyboards out there which don't allow this combination due to a messed up keyboard switch matrix.

This article is interesting too: http://en.wikipedia.org/wiki/Rollover_(key)
(Sorry, broken link due to phpBB)