summaryrefslogtreecommitdiff
path: root/src/keyboardconfig.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-03-09 17:13:34 +0300
committerAndrei Karas <akaras@inbox.ru>2012-03-09 17:13:34 +0300
commite6bb33fad96878b66ecb32c104d06cd6e5ea9e77 (patch)
tree9294304f6480140a1cb0383df395893ae7009db7 /src/keyboardconfig.cpp
parent443813146a327504a07a507f43117d92296ca8a7 (diff)
downloadmv-e6bb33fad96878b66ecb32c104d06cd6e5ea9e77.tar.gz
mv-e6bb33fad96878b66ecb32c104d06cd6e5ea9e77.tar.bz2
mv-e6bb33fad96878b66ecb32c104d06cd6e5ea9e77.tar.xz
mv-e6bb33fad96878b66ecb32c104d06cd6e5ea9e77.zip
Add limited support for keys unknown for SDL.
This keys can be assigned to simple actions and cant be modifier keys.
Diffstat (limited to 'src/keyboardconfig.cpp')
-rw-r--r--src/keyboardconfig.cpp58
1 files changed, 49 insertions, 9 deletions
diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp
index eac641b5a..cf620148e 100644
--- a/src/keyboardconfig.cpp
+++ b/src/keyboardconfig.cpp
@@ -456,9 +456,18 @@ void KeyboardConfig::callbackNewKey()
mSetupKey->newKeyCallback(mNewKeyIndex);
}
+int KeyboardConfig::getKeyValueFromEvent(const SDL_Event &event) const
+{
+ if (event.key.keysym.sym)
+ return event.key.keysym.sym;
+ else if (event.key.keysym.scancode > 1)
+ return -event.key.keysym.scancode;
+ return 0;
+}
+
int KeyboardConfig::getKeyIndex(const SDL_Event &event, int grp) const
{
- const int keyValue = event.key.keysym.sym;
+ const int keyValue = getKeyValueFromEvent(event);
for (int i = 0; i < KEY_TOTAL; i++)
{
if (keyValue == mKey[i].value &&
@@ -473,7 +482,7 @@ int KeyboardConfig::getKeyIndex(const SDL_Event &event, int grp) const
int KeyboardConfig::getKeyEmoteOffset(const SDL_Event &event) const
{
- const int keyValue = event.key.keysym.sym;
+ const int keyValue = getKeyValueFromEvent(event);
for (int i = KEY_EMOTE_1; i <= KEY_EMOTE_48; i++)
{
if (keyValue == mKey[i].value)
@@ -486,7 +495,11 @@ bool KeyboardConfig::isActionActive(int index) const
{
if (!mActiveKeys)
return false;
- return mActiveKeys[mKey[index].value];
+ const int value = mKey[index].value;
+ if (value >= 0)
+ return mActiveKeys[value];
+ else
+ return false; // scan codes active state now not implimented
}
void KeyboardConfig::refreshActiveKeys()
@@ -494,20 +507,47 @@ void KeyboardConfig::refreshActiveKeys()
mActiveKeys = SDL_GetKeyState(nullptr);
}
-std::string KeyboardConfig::getKeyValueString(int index) const
+std::string KeyboardConfig::getKeyStringLong(int index) const
{
- std::string key = SDL_GetKeyName(
- static_cast<SDLKey>(getKeyValue(index)));
+ const int keyValue = getKeyValue(index);
+ if (keyValue >= 0)
+ return SDL_GetKeyName(static_cast<SDLKey>(keyValue));
+ else if (keyValue < -1)
+ return strprintf(_("key_%d"), -keyValue);
+ else
+ return _("unknown key");
+}
- return getKeyShortString(key);
+std::string KeyboardConfig::getKeyValueString(int index) const
+{
+ const int keyValue = getKeyValue(index);
+ if (keyValue >= 0)
+ {
+ std::string key = SDL_GetKeyName(static_cast<SDLKey>(keyValue));
+ return getKeyShortString(key);
+ }
+ else if (keyValue < -1)
+ {
+ return strprintf("#%d", -keyValue);
+ }
+ else
+ {
+ // TRANSLATORS: Unknown key short string. This string must be maximum 5 chars
+ return _("u key");
+ }
}
std::string KeyboardConfig::getKeyShortString(const std::string &key) const
{
if (key == "backspace")
+ {
return "bksp";
+ }
else if (key == "unknown key")
- return "u key";
+ {
+ // TRANSLATORS: Unknown key short string. This string must be maximum 5 chars
+ return _("u key");
+ }
return key;
}
@@ -518,7 +558,7 @@ SDLKey KeyboardConfig::getKeyFromEvent(const SDL_Event &event) const
void KeyboardConfig::setNewKey(const SDL_Event &event)
{
- mKey[mNewKeyIndex].value = event.key.keysym.sym;
+ mKey[mNewKeyIndex].value = getKeyValueFromEvent(event);
}
void KeyboardConfig::unassignKey()