Problem with the input from keyboard

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
JBoss
Posts: 7
Joined: Fri Jun 10, 2011 4:12 pm

Problem with the input from keyboard

Post by JBoss »

Hi guys
sorry for my english, because I'm italian.
I've a problem with the input from keyboard, I set that when S is pressed to
write in the console a string, but when I press it, it compares a lot of times, How can I solve this type of issue? Thank you!
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

well it is creating a positive result since you are holding it down. I'm guessing what you want is a single pulse?
ent1ty wrote: success is a matter of concentration and desire
Butler Lampson wrote: all problems in Computer Science can be solved by another level of indirection
at a cost measure in computer resources ;)
JBoss
Posts: 7
Joined: Fri Jun 10, 2011 4:12 pm

Post by JBoss »

yes!
JBoss
Posts: 7
Joined: Fri Jun 10, 2011 4:12 pm

Post by JBoss »

Is It possible? :?:
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Not so easy, no.
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
JBoss
Posts: 7
Joined: Fri Jun 10, 2011 4:12 pm

Post by JBoss »

Ok! Thank You!
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

I do not have access to my code atm but what you need is just another kind of input manager that re-dispatches events but uses bool locks to see if that event was already continuously sent. it locks up once it is sent and only unlocks when the event is not being received.
ent1ty wrote: success is a matter of concentration and desire
Butler Lampson wrote: all problems in Computer Science can be solved by another level of indirection
at a cost measure in computer resources ;)
KP84
Posts: 44
Joined: Thu Feb 24, 2011 5:08 am

Post by KP84 »

modified from tutorial 4: movement

Code: Select all

class MyEventReceiver : public IEventReceiver
{
public:
        // This is the one method that we have to implement
        virtual bool OnEvent(const SEvent& event)
        {
					
	if (event.EventType == irr::EET_KEY_INPUT_EVENT)
	{
						
						// There is one known bug. It will work but when you press
						// first the else{...} is executed and then the next time passing
						// this if statement the {...}else us run
						if( KeyIsDown[ KEY_KEY_S ] )
						{
							
							// print the str
							KeyIsDown[ KEY_KEY_S ] = false;

						} else
						{
							
							KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
								
						};

					};

          return false;
					
				}

        MyEventReceiver()
        {
                for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
                        KeyIsDown[i] = false;
        }

private:
        bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
something like this should work

EDIT: previous message wich I did post half deleted. Really somethimes I am in need of an update myself.

Code: Select all

// if you think real code is always interresting, read this line again
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

You could also use two arrays for last and current key state and compare those two.
So if last time the key was up and now its pressed, you can get that single press.
Working on game: Marrbles (Currently stopped).
Post Reply