Exemplo n.º 1
0
Uint32 KeyboardManager::getAction(const KeyPress& key)
{
	//This is to solve a bug due to the system recieving the key-up event
	//which is not included in multiple-key sequences
	if(key.getPressed() || lastPresses.empty())
		lastPresses.push_back(key);
	int matches = 0;
	KeyboardShortcut lastMatch;
	for(std::list<KeyboardShortcut>::iterator i = shortcuts.begin(); i!=shortcuts.end(); ++i)
	{
		if(lastPresses.size() > i->getKeyPressCount())
			continue;
		
		bool matched=true;
		for(size_t j=0; j<lastPresses.size(); ++j)
		{
			if(i->getKeyPress(j) != lastPresses[j])
			{
				matched=false;
				break;
			}
		}
		if(matched == true)
		{
			lastMatch = *i;
			matches += 1;
		}
	}
	if(matches == 0)
	{
		lastPresses.clear();
		return GameGUIKeyActions::DoNothing;
	}
	else if(matches == 1)
	{
		lastPresses.clear();
		return lastMatch.getAction();
	}
	return GameGUIKeyActions::DoNothing;
}