Author Topic: Configurable Hotkeys  (Read 2196 times)

hailstone

  • GAE Team
  • Battle Machine
  • ********
  • Posts: 1,568
    • View Profile
Configurable Hotkeys
« on: 6 February 2008, 02:29:00 »
Basically what I did was create a modified version of the Config class which loads an ini file through the Properties class.

Code: [Select]
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
Code: [Select]
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
« Last Edit: 1 January 1970, 00:00:00 by hailstone »
Glest Advanced Engine - Admin/Programmer
https://sourceforge.net/projects/glestae/

daniel.santos

  • Guest
(No subject)
« Reply #1 on: 6 February 2008, 05:47:49 »
very awesome hailstone! :)
« Last Edit: 1 January 1970, 00:00:00 by daniel.santos »

greenmanwitch

  • Guest
(No subject)
« Reply #2 on: 21 April 2008, 00:09:00 »
Hi! First post :).

I'm somewhat confused. I didn't have a global file so I created one, copied over the keys.cpp and keys.h files into there and left the hotkeys.ini file in glest_game/

Now what...?
« Last Edit: 1 January 1970, 00:00:00 by greenmanwitch »

ZaggyDad

  • Guest
(No subject)
« Reply #3 on: 21 April 2008, 02:08:15 »
You have to put the files in with the glest code and compile it. (which is very complicated (for me, at least) )

~Zaggy
« Last Edit: 1 January 1970, 00:00:00 by ZaggyDad »

daniel.santos

  • Guest
(No subject)
« Reply #4 on: 21 April 2008, 03:34:27 »
crap, I had so much going on when this was posted that I completely forgot about it :(  I'm going to merge this into GAE
« Last Edit: 1 January 1970, 00:00:00 by daniel.santos »

hailstone

  • GAE Team
  • Battle Machine
  • ********
  • Posts: 1,568
    • View Profile
(No subject)
« Reply #5 on: 21 April 2008, 13:25:03 »
Thanks, I'm interested to know how you fix up the gaps I left. ie. using combination keys
« Last Edit: 1 January 1970, 00:00:00 by hailstone »
Glest Advanced Engine - Admin/Programmer
https://sourceforge.net/projects/glestae/

 

anything