Multiple keys pressed

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
raytaller
Posts: 17
Joined: Wed Feb 07, 2007 11:28 am

Multiple keys pressed

Post 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 ?
CuteAlien
Admin
Posts: 9689
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post 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).
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
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post 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.
Kalango
Posts: 157
Joined: Thu Apr 26, 2007 12:46 am

Post 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...
raytaller
Posts: 17
Joined: Wed Feb 07, 2007 11:28 am

Post 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);
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post 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)
"Whoops..."
Post Reply