示例#1
0
bool CKeyBindings::ExecuteCommand(const std::string& line)
{
	const std::vector<std::string> words = CSimpleParser::Tokenize(line, 2);

	if (words.empty()) {
		return false;
	}
	const std::string command = StringToLower(words[0]);

	if (command == "keydebug") {
		if (words.size() == 1) {
			// toggle
			debugEnabled = !debugEnabled;
		} else if (words.size() >= 2) {
			// set
			debugEnabled = atoi(words[1].c_str());
		}
	}
	else if ((command == "fakemeta") && (words.size() > 1)) {
		if (!SetFakeMetaKey(words[1])) { return false; }
	}
	else if ((command == "keysym") && (words.size() > 2)) {
		if (!AddKeySymbol(words[1], words[2])) { return false; }
	}
	else if ((command == "bind") && (words.size() > 2)) {
		if (!Bind(words[1], words[2])) { return false; }
	}
	else if ((command == "unbind") && (words.size() > 2)) {
		if (!UnBind(words[1], words[2])) { return false; }
	}
	else if ((command == "unbindaction") && (words.size() > 1)) {
		if (!UnBindAction(words[1])) { return false; }
	}
	else if ((command == "unbindkeyset") && (words.size() > 1)) {
		if (!UnBindKeyset(words[1])) { return false; }
	}
	else if (command == "unbindall") {
		bindings.clear();
		keyCodes->Reset();
		Bind("enter", "chat"); // bare minimum
	}
	else {
		return false;
	}

	if (buildHotkeyMap) {
		BuildHotkeyMap();
	}

	return false;
}
示例#2
0
bool CKeyBindings::Load(const std::string& filename)
{
    CFileHandler ifs(filename);
    CSimpleParser parser(ifs);
    buildHotkeyMap = false; // temporarily disable BuildHotkeyMap() calls
    LoadDefaults();

    while (!parser.Eof()) {
        const std::string line = parser.GetCleanLine();
        ExecuteCommand(line);
    }

    BuildHotkeyMap();
    buildHotkeyMap = true; // re-enable BuildHotkeyMap() calls
    return true;
}
示例#3
0
void CKeyBindings::Sanitize()
{
	// FIXME -- do something extra here?
	//          (seems as though removing the Up states fixed most of the problems)
	BuildHotkeyMap();
}