key input & XML

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
morph
Posts: 10
Joined: Sun Jun 03, 2007 10:19 pm

key input & XML

Post by morph »

how can i write a code that reads from an xml file what key i must press for what action

greets Morph
evo
Posts: 96
Joined: Mon Jun 27, 2005 6:46 pm
Location: The Netherlands

Post by evo »

Hi,

Reply is a bit late, but anyway:

There is plenty of documentation and examples how to read from an xml file. For mapping key input to desired action you might do something like this:

Code: Select all

//pseudo code

struct	map {
				key			irr::u8;
				function	irr::u16;
			};

core::array<MyMap>	map;


init()
{
		map			tmp;

while (not end of xml)
	'read from xml file here into tmp
	map.push_back(tmp)
};

irr::u8 get key pressed()
// some funtion to translate enum into u8
// maybe use number value associated wih Irrlicht enum EKEY_CODE to keep it simple

//inputreceiver
bool OnEvent(SEvent event)
{
	irr::u8 key = get key pressed();

	for(irr::u16 i=0; i<map.size(); i++)
	{
		if (map[i].key == key)
			{f = map[i].function; break;}
	}


	switch (f)
		case 1 : do_action_1;
		case 2 : do_action_2;
		case n : do_action_n;

}
Post Reply