void JoystickKeyboardController::process_key_event(const SDL_KeyboardEvent& event) { KeyMap::iterator key_mapping = keymap.find(event.keysym.sym); // if console key was pressed: toggle console if ((key_mapping != keymap.end()) && (key_mapping->second == Controller::CONSOLE)) { if (event.type == SDL_KEYDOWN) Console::instance->toggle(); } else { if (Console::instance->hasFocus()) { // if console is open: send key there process_console_key_event(event); } else if (MenuManager::current()) { // if menu mode: send key there process_menu_key_event(event); } else if(key_mapping == keymap.end()) { // default action: update controls //log_debug << "Key " << event.key.keysym.sym << " is unbound" << std::endl; } else { Control control = key_mapping->second; bool value = (event.type == SDL_KEYDOWN); controller->set_control(control, value); if (jump_with_up_kbd && control == Controller::UP){ controller->set_control(Controller::JUMP, value); } } } }
void KeyboardManager::process_key_event(const SDL_KeyboardEvent& event) { KeyboardConfig::KeyMap::iterator key_mapping = m_keyboard_config.keymap.find(event.keysym.sym); // if console key was pressed: toggle console if (key_mapping != m_keyboard_config.keymap.end() && key_mapping->second == Controller::CONSOLE) { if (event.type == SDL_KEYDOWN) { // text input gets locked between the console-key being pressed // and released to avoid the console-key getting interpreted as // text input and echoed to the console m_lock_text_input = true; Console::current()->toggle(); } else if (event.type == SDL_KEYUP) { m_lock_text_input = false; } } else if (Console::current()->hasFocus()) { // if console is open: send key there process_console_key_event(event); } else if (MenuManager::instance().is_active()) { // if menu mode: send key there process_menu_key_event(event); } else if (key_mapping == m_keyboard_config.keymap.end()) { // default action: update controls //log_debug << "Key " << event.key.SDL_Keycode.sym << " is unbound" << std::endl; } else { auto control = key_mapping->second; bool value = (event.type == SDL_KEYDOWN); m_parent->get_controller()->set_control(control, value); if (m_keyboard_config.jump_with_up_kbd && control == Controller::UP) { m_parent->get_controller()->set_control(Controller::JUMP, value); } } }