Example #1
0
void InputSystem::init() {
	SDL_SetRelativeMouseMode(SDL_TRUE);

	key_binds["P"] = KeyBind("P", "Reset");
	
	
	key_binds["Space"] = KeyBind("Space", "Jump");
	key_binds["F"] = KeyBind("F", "Fire");
	
	axis_binds["W"] = AxisBind("W", "MoveForward", -1.0f);
	axis_binds["S"] = AxisBind("S", "MoveForward", 1.0f);

	axis_binds["A"] = AxisBind("A", "MoveRight", -1.0f);
	axis_binds["D"] = AxisBind("D", "MoveRight", 1.0f);

	axis_binds["Q"] = AxisBind("Q", "Turn", -1.0f);
	axis_binds["E"] = AxisBind("E", "Turn", 1.0f);
	
	axis_binds["Left"] = AxisBind("Left", "CameraX", 1.0f);
	axis_binds["Right"] = AxisBind("Right", "CameraX", -1.0f);
	axis_binds["Up"] = AxisBind("Up", "CameraY", 1.0f);
	axis_binds["Down"] = AxisBind("Down", "CameraY", -1.0f);

	axis_binds["MouseX"] = AxisBind("MouseX", "TurnAt", 1.0f);

}
Example #2
0
/* KeyBind::addBind
 * Adds a new keybind
 *******************************************************************/
bool KeyBind::addBind(string name, keypress_t key, string desc, string group, bool ignore_shift, int priority)
{
    // Find keybind
    KeyBind* bind = NULL;
    for (unsigned a = 0; a < keybinds.size(); a++)
    {
        if (keybinds[a].name == name)
        {
            bind = &keybinds[a];
            break;
        }
    }

    // Add keybind if it doesn't exist
    if (!bind)
    {
        keybinds.push_back(KeyBind(name));
        bind = &keybinds.back();
        bind->ignore_shift = ignore_shift;
    }

    // Set keybind description/group
    if (!desc.IsEmpty())
    {
        bind->description = desc;
        bind->group = group;
    }

    // Check if the key is already bound to it
    for (unsigned a = 0; a < bind->keys.size(); a++)
    {
        if (bind->keys[a].alt == key.alt &&
                bind->keys[a].ctrl == key.ctrl &&
                bind->keys[a].shift == key.shift &&
                bind->keys[a].key == key.key)
        {
            // It is, remove the bind
            bind->keys.erase(bind->keys.begin() + a);
            return false;
        }
    }

    // Set priority
    if (priority >= 0)
        bind->priority = priority;

    // Add the keybind
    bind->addKey(key.key, key.alt, key.ctrl, key.shift);

    return true;
}