Basically what I did was create a modified version of the Config class which loads an ini file through the Properties class.
const char Keys::getKey(const string &commandName) const{
string key = properties.getString(commandName);
if (key == "ESCAPE"){
return vkEscape;
} else if (key == "ADD"){
return vkAdd;
} else if (key == "SUBTRACT"){
return vkSubtract;
} else if (key == "LEFT"){
return vkLeft;
} else if (key == "RIGHT"){
return vkRight;
} else if (key == "UP"){
return vkUp;
} else if (key == "DOWN"){
return vkDown;
} else {
char c = key[0]; // remove trailing null char
return toupper(c);
}
return 0;
}
This is the most important method in the Keys class.
When called like
Keys &keys= Keys::getInstance();
if(key==keys.getKey("SaveScreen")){
the command name is used to return the associated hotkey that is in hotkeys.ini (ie SaveScreen=E). If the hotkey is a 'special' one (not a number or letter) it returns the platform's representation of that key. I'm not sure how to implement combination keys such as ALT+RETURN.
These are places where hotkeys are used in the source:
-- glest_game/game/game.cpp
void Game::keyDown(char key)
void Game::keyUp(char key)
-- glest_game/gui/gui.cpp
void Gui::hotKey(char key)
void Gui::groupKey(int groupIndex)
void Gui::computeSelected(bool doubleClick)
-- glest_game/main/program.cpp
void Program::keyDown(char key)
void Program::keyUp(char key) (cant be used with the switch)
I put keys.cpp/h in glest_game/global/ and hotkeys.ini in Glest root
configurable_hotkeys.tar.gz