From 8f3be5cd0544af07c6cb65bef7a1f3ba1a3704bb Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 9 Apr 2012 23:59:46 +0300 Subject: Fix asigning keys unknown for SDL. Allow full use of keys unknown for SDL (with press state also). --- src/inputmanager.cpp | 45 ++++++++++++++++++++++++++++----------------- src/keyboardconfig.cpp | 32 +++++++++++++++++++++++++++++--- src/keyboardconfig.h | 6 ++++++ 3 files changed, 63 insertions(+), 20 deletions(-) diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp index b539c4bcf..3c73376df 100644 --- a/src/inputmanager.cpp +++ b/src/inputmanager.cpp @@ -156,7 +156,7 @@ void InputManager::store() default: break; } - if (key.value >= 0) + if (key.value != -1) { if (keyStr.empty()) { @@ -264,16 +264,17 @@ std::string InputManager::getKeyStringLong(int index) const const KeyItem &key = mKey[index].values[i]; if (key.type == INPUT_KEYBOARD) { + std::string str; if (key.value >= 0) + str = keyboard.getKeyName(key.value); + else if (key.value < -1) + str = strprintf(_("key_%d"), -key.value); + if (!str.empty()) { - std::string str = keyboard.getKeyName(key.value); - if (!str.empty()) - { - if (keyStr.empty()) - keyStr = str; - else - keyStr += std::string(" ") + str; - } + if (keyStr.empty()) + keyStr = str; + else + keyStr += std::string(" ") + str; } } } @@ -292,17 +293,22 @@ std::string InputManager::getKeyValueString(int index) const const KeyItem &key = mKey[index].values[i]; if (key.type == INPUT_KEYBOARD) { + std::string str; if (key.value >= 0) { - std::string str = keyboard.getKeyShortString( + str = keyboard.getKeyShortString( keyboard.getKeyName(key.value)); - if (!str.empty()) - { - if (keyStr.empty()) - keyStr = str; - else - keyStr += std::string(" ") + str; - } + } + else if (key.value < -1) + { + str = strprintf(_("key_%d"), -key.value); + } + if (!str.empty()) + { + if (keyStr.empty()) + keyStr = str; + else + keyStr += std::string(" ") + str; } } } @@ -382,6 +388,7 @@ bool InputManager::handleEvent(const SDL_Event &event) if (handleAssignKey(event)) return true; + keyboard.handleActicateKey(event); // send straight to gui for certain windows if (quitDialog || TextDialog::isActive() || NpcPostDialog::isActive()) @@ -401,6 +408,10 @@ bool InputManager::handleEvent(const SDL_Event &event) return true; } } + else if (event.type == SDL_KEYUP) + { + keyboard.handleDeActicateKey(event); + } try { diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp index 483b7d511..ae095f01d 100644 --- a/src/keyboardconfig.cpp +++ b/src/keyboardconfig.cpp @@ -39,13 +39,17 @@ KeyboardConfig::KeyboardConfig() : mEnabled(true), - mActiveKeys(nullptr) + mActiveKeys(nullptr), + mActiveKeys2(nullptr) { } void KeyboardConfig::init() { mEnabled = true; + if (mActiveKeys2) + delete mActiveKeys2; + mActiveKeys2 = new Uint8[500]; } int KeyboardConfig::getKeyValueFromEvent(const SDL_Event &event) const @@ -144,8 +148,16 @@ bool KeyboardConfig::isActionActive(int index) const for (size_t i = 0; i < KeyFunctionSize; i ++) { const int value = inputManager.getKey(index).values[i].value; - if (value >= 0 && mActiveKeys[value]) - return true; + if (value >= 0) + { + if (mActiveKeys[value]) + return true; + } + else if (value < -1 && value > -500) + { + if (mActiveKeys2[-value]) + return true; + } } return false; } @@ -154,3 +166,17 @@ void KeyboardConfig::update() { inputManager.updateKeyActionMap(mKeyToAction, INPUT_KEYBOARD); } + +void KeyboardConfig::handleActicateKey(const SDL_Event &event) +{ + const int key = getKeyValueFromEvent(event); + if (key < -1 && key > -500) + mActiveKeys2[-key] = 1; +} + +void KeyboardConfig::handleDeActicateKey(const SDL_Event &event) +{ + const int key = getKeyValueFromEvent(event); + if (key < -1 && key > -500) + mActiveKeys2[-key] = 0; +} diff --git a/src/keyboardconfig.h b/src/keyboardconfig.h index 4d57acc7f..ce09de898 100644 --- a/src/keyboardconfig.h +++ b/src/keyboardconfig.h @@ -81,11 +81,17 @@ class KeyboardConfig void update(); + void handleActicateKey(const SDL_Event &event); + + void handleDeActicateKey(const SDL_Event &event); + private: bool mEnabled; /**< Flag to respond to key input */ Uint8 *mActiveKeys; /**< Stores a list of all the keys */ + Uint8 *mActiveKeys2; /**< Stores a list of all the keys */ + KeyToActionMap mKeyToAction; }; -- cgit v1.2.3-60-g2f50