From da0ccd99e830bbe77f97096df72d5a78f6459d5f Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Mon, 25 Sep 2023 02:30:35 +0200 Subject: [PATCH] try to use translated key names --- config/ConfigFormUnit.cpp | 87 ++++++++++++++++++++------------------- config/ConfigFormUnit.h | 3 +- 2 files changed, 47 insertions(+), 43 deletions(-) diff --git a/config/ConfigFormUnit.cpp b/config/ConfigFormUnit.cpp index acd2b4b..1a9e4f7 100644 --- a/config/ConfigFormUnit.cpp +++ b/config/ConfigFormUnit.cpp @@ -16,6 +16,7 @@ TConfigForm *ConfigForm; bool Initialized; bool IsEnglish; +System::UnicodeString KeyNames[256]; /* Save previous settings so we don't override custom settings */ int Maxfps; @@ -1235,11 +1236,11 @@ WORD TConfigForm::GetKeyCode(System::UnicodeString key) return VK_PAUSE; } - if (key == L"R " + TranslateShortCut(ShortCutToText(VK_CONTROL))) { + if (key == L"R " + KeyToText(VK_CONTROL)) { return VK_RCONTROL; } - return TextToShortCut(TranslateShortCut(key)); + return TextToKey(key); } System::UnicodeString TConfigForm::GetKeyText(WORD key) @@ -1253,55 +1254,57 @@ System::UnicodeString TConfigForm::GetKeyText(WORD key) } if (key == VK_RCONTROL) { - return L"R " + TranslateShortCut(ShortCutToText(VK_CONTROL)); + return L"R " + KeyToText(VK_CONTROL); } if (key == VK_RSHIFT) { - return TranslateShortCut(ShortCutToText(VK_SHIFT)); + return KeyToText(VK_SHIFT); } - return TranslateShortCut(ShortCutToText(key)); + return KeyToText(key); } -System::UnicodeString TConfigForm::TranslateShortCut(System::UnicodeString text) +WORD TConfigForm::TextToKey(System::UnicodeString Text) { - /* Hack: Allows building the config tool on a german OS */ - if (text == "Eingabe") return "Enter"; - if (text == "Enter") return "Eingabe"; - if (text == "Leer") return "Space"; - if (text == "Space") return "Leer"; - if (text == "BildAuf") return "PgUp"; - if (text == "PgUp") return "BildAuf"; - if (text == "BildAb") return "PgDn"; - if (text == "PgDn") return "BildAb"; - if (text == "Ende") return "End"; - if (text == "End") return "Ende"; - if (text == "Pos1") return "Home"; - if (text == "Home") return "Pos1"; - if (text == "Links") return "Left"; - if (text == "Left") return "Links"; - if (text == "Auf") return "Up"; - if (text == "Up") return "Auf"; - if (text == "Rechts") return "Right"; - if (text == "Right") return "Rechts"; - if (text == "Ab") return "Down"; - if (text == "Down") return "Ab"; - if (text == "Einfg") return "Ins"; - if (text == "Ins") return "Einfg"; - if (text == "UMSCHALT") return "Shift"; - if (text == "Shift") return "UMSCHALT"; - if (text == "STRG") return "Ctrl"; - if (text == "Ctrl") return "STRG"; - if (text == "ALT") return "Alt"; - if (text == "Alt") return "ALT"; - if (text == "CTRL") return "Ctrl"; - if (text == "Ctrl") return "CTRL"; - if (text == "ROLLEN-FESTSTELL") return "Scroll Lock"; - if (text == "Scroll Lock") return "ROLLEN-FESTSTELL"; - if (text == "FESTSTELL") return "Caps Lock"; - if (text == "Caps Lock") return "FESTSTELL"; + for (WORD i = 0; i < 256; i++) { + if (KeyNames[i] == Text) { + return i; + } + } - return text; + return 0; +} + +System::UnicodeString TConfigForm::KeyToText(WORD key) +{ + WCHAR keyName[256] = {}; + + UINT scanCode = MapVirtualKeyW(key, MAPVK_VK_TO_VSC); + + switch (key) { + case VK_LEFT: + case VK_UP: + case VK_RIGHT: + case VK_DOWN: + case VK_PRIOR: + case VK_NEXT: + case VK_END: + case VK_HOME: + case VK_INSERT: + case VK_DELETE: + case VK_DIVIDE: + case VK_NUMLOCK: + { + scanCode |= 0x100; + break; + } + } + + GetKeyNameTextW(scanCode << 16, keyName, sizeof(keyName) / sizeof(WCHAR)); + + KeyNames[(BYTE)key] = keyName; + + return KeyNames[(BYTE)key]; } bool TConfigForm::GetBool(TIniFile *ini, System::UnicodeString key, bool defValue) diff --git a/config/ConfigFormUnit.h b/config/ConfigFormUnit.h index f521d0f..83ed66a 100644 --- a/config/ConfigFormUnit.h +++ b/config/ConfigFormUnit.h @@ -124,7 +124,8 @@ private: // Benutzer-Deklarationen void ApplyTranslation(TIniFile *ini); System::UnicodeString GetKeyText(WORD key); WORD GetKeyCode(System::UnicodeString key); - System::UnicodeString TranslateShortCut(System::UnicodeString text); + WORD TextToKey(System::UnicodeString Text); + System::UnicodeString KeyToText(WORD key); public: // Benutzer-Deklarationen __fastcall TConfigForm(TComponent* Owner); };