From dce054c87175e8b05dd41e546af04a6ef89b2d0b Mon Sep 17 00:00:00 2001 From: Marcel Houweling Date: Mon, 9 Aug 2021 17:41:40 +0200 Subject: [PATCH] The bound key is shown in the dropdown, localised for the current keyboard language (So: US keyboard shows WSAD, French keyboard shows ZSQD) --- .../WindowsInput/Native/DirectInputKeyCode.cs | 184 +---- README.md | 6 +- starcitizen/CommandTools.cs | 630 +++++++++++++++++- starcitizen/KeyboardLayouts.cs | 122 ++++ starcitizen/Properties/AssemblyInfo.cs | 4 +- starcitizen/SC/DProfileReader.cs | 23 +- starcitizen/manifest.json | 2 +- starcitizen/starcitizen.csproj | 1 + 8 files changed, 788 insertions(+), 184 deletions(-) create mode 100644 starcitizen/KeyboardLayouts.cs diff --git a/InputSimulatorPlus/WindowsInput/Native/DirectInputKeyCode.cs b/InputSimulatorPlus/WindowsInput/Native/DirectInputKeyCode.cs index 3ee73ab..a95dd5d 100644 --- a/InputSimulatorPlus/WindowsInput/Native/DirectInputKeyCode.cs +++ b/InputSimulatorPlus/WindowsInput/Native/DirectInputKeyCode.cs @@ -3,6 +3,13 @@ /// /// The list of DirectInput keyboard scan codes from dinput.h in dxsdk /// + /// + /// FIRST ROW DIKGRAVE DIKMINUS DIKEQUALS + /// SECOND ROW DIKLBRACKET DIKRBRACKET DIKBACKSLASH + /// THIRD ROW DIKSEMICOLON DIKAPOSTROPHE + /// FOURTH ROW DIKCOMMA DIKPERIOD DIKSLASH + + /// public enum DirectInputKeyCode { /// @@ -60,7 +67,7 @@ public enum DirectInputKeyCode /// /// Backspace key /// - DikBack = 0x0E, + DikBackspace = 0x0E, /// /// Tab key /// @@ -228,7 +235,7 @@ public enum DirectInputKeyCode /// /// Left alt key /// - DikLmenu = 0x38, + DikLalt = 0x38, /// /// ' ' key /// @@ -560,7 +567,7 @@ public enum DirectInputKeyCode /// /// Right alt key /// - DikRmenu = 0xB8, + DikRalt = 0xB8, /// /// Pause key /// @@ -576,7 +583,7 @@ public enum DirectInputKeyCode /// /// PageUp key on arrow keypad /// - DikPrior = 0xC9, + DikPageUp = 0xC9, /// /// Left arrow key on arrow keypad /// @@ -596,7 +603,7 @@ public enum DirectInputKeyCode /// /// PageDown key on arrow keypad /// - DikNext = 0xD1, + DikPageDown = 0xD1, /// /// Insert key on arrow keypad /// @@ -665,173 +672,6 @@ public enum DirectInputKeyCode /// Media select /// DikMediaselect = 0xED, - /// - /// PageUp key on arrow keypad - /// - DikPageUp = DikPrior, - /// - /// PageDown key on arrow keypad - /// - DikPageDown = DikNext, - /// - /// Backspace key - /// - DikBackspace = DikBack, - /// - /// '*' key on numeric keypad - /// - DikNumpadStar = DikMultiply, - /// - /// Left alt key - /// - DikLalt = DikLmenu, - /// - /// Caps lock key - /// - DikCapslock = DikCapital, - /// - /// '-' key on numeric keypad - /// - DikNumpadMinus = DikSubtract, - /// - /// '+' key on numeric keypad - /// - DikNumpadPlus = DikAdd, - /// - /// '.' key on numeric keypad - /// - DikNumpadPeriod = DikDecimal, - /// - /// '/' key on numeric keypad - /// - DikNumpadSlash = DikDivide, - /// - /// Right alt key - /// - DikRalt = DikRmenu, - /// - /// Up arrow key on arrow keypad - /// - DikUparrow = DikUp, - /// - /// PageUp key on arrow keypad - /// - DikPgup = DikPrior, - /// - /// Left arrow key on arrow keypad - /// - DikLeftarrow = DikLeft, - /// - /// Right arrow key on arrow keypad - /// - DikRightarrow = DikRight, - /// - /// Down arrow key on arrow keypad - /// - DikDownarrow = DikDown, - /// - /// PageDown key on arrow keypad - /// - DikPgdn = DikNext, - - /// - /// - DikEnter = DikReturn, - /// - /// - DikNumpad_Equals = DikNumpadequals, - /// - /// - DikNumpad_Enter = DikNumpadenter, - /// - /// - DikNumpad_Comma = DikNumpadcomma, - - /// - /// - DikNumpad_Divide = DikNumpadSlash, - /// - /// - DikNumpadDivide = DikNumpadSlash, - /// - /// - DikNumpad_Multiply = DikNumpadStar, - /// - /// - DikNumpadMultiply = DikNumpadStar, - /// - /// - DikNumpad_Subtract = DikNumpadMinus, - /// - /// - DikNumpadSubtract = DikNumpadMinus, - /// - /// - DikNumpad_Decimal = DikNumpadPeriod, - /// - /// - DikNumpadDecimal = DikNumpadPeriod, - /// - /// - DikNumpad_Add = DikNumpadPlus, - /// - /// - DikNumpadAdd = DikNumpadPlus, - /// - /// - DikNumpad_7 = DikNumpad7, - /// - /// - DikNumpad_8 = DikNumpad8, - /// - /// - DikNumpad_9 = DikNumpad9, - /// - /// - DikNumpad_4 = DikNumpad4, - /// - /// - DikNumpad_5 = DikNumpad5, - /// - /// - DikNumpad_6 = DikNumpad6, - /// - /// - DikNumpad_1 = DikNumpad1, - /// - /// - DikNumpad_2 = DikNumpad2, - /// - /// - DikNumpad_3 = DikNumpad3, - /// - /// - DikNumpad_0 = DikNumpad0, - /// - /// - DikLeftBracket = DikLbracket, - /// - /// - DikRightBracket = DikRbracket, - - /// - /// - DikLeftAlt = DikLmenu, - /// - /// - DikRightAlt = DikRmenu, - /// - /// - DikRightControl = DikRcontrol, - /// - /// - DikLeftControl = DikLcontrol, - /// - /// - DikRightShift = DikRshift, - /// - /// - DikLeftShift = DikLshift /* diff --git a/README.md b/README.md index 4b69e35..8237454 100644 --- a/README.md +++ b/README.md @@ -6,15 +6,17 @@ TODO : **Elgato Stream Deck button plugin for Star Citizen** -![Elgato Stream Deck button plugin for Star Citizen](https://i.imgur.com/SgsPN2d.png) +![Elgato Stream Deck button plugin for Star Citizen](https://i.imgur.com/FSHsXRG.png) This plugin gets the key bindings from the Star Citizen game files. The bindings in the streamdeck plugin are automatically updated when changing bindings in Star Citizen options screen. +The key is shown in the dropdown, localised for the current keyboard language (So: US keyboard shows WSAD, French keyboard shows ZSQD) + **The plugin does not contain any button images or ready made streamdeck profiles.** -Credit goes to https://github.com/SCToolsfactory/SCJMapper-V2 for all the code to get the defaultProfile.xml from the pk4 file etc. +Credit goes to https://github.com/SCToolsfactory/SCJMapper-V2 for all the code to get the defaultProfile.xml from the p4k file etc. The button works in a similar way, to the streamdeck 'Hotkey' button type. So, there is only one image and there is no game state feedback for these buttons. diff --git a/starcitizen/CommandTools.cs b/starcitizen/CommandTools.cs index 5c868c0..5ca44c5 100644 --- a/starcitizen/CommandTools.cs +++ b/starcitizen/CommandTools.cs @@ -24,18 +24,636 @@ public static string ConvertKeyString(string keyboard) return keyboard; } + + public static string ConvertKeyStringToLocale(string keyboard, string language) + { + var keys = keyboard.Split('+'); + keyboard = ""; + foreach (var key in keys) + { + var dikKey = FromSCKeyboardCmd(key); + + var dikKeyOut = dikKey.ToString(); + + switch (language) + { + case "en-GB": + // http://kbdlayout.info/kbduk/shiftstates+scancodes/base + + switch (dikKey) + { + // FIRST ROW + case DirectInputKeyCode.DikGrave: + + dikKeyOut = "Dik`"; + break; + + case DirectInputKeyCode.DikMinus: + dikKeyOut = "Dik-"; + break; + + case DirectInputKeyCode.DikEquals: + dikKeyOut = "Dik="; + break; + + // SECOND ROW + + case DirectInputKeyCode.DikLbracket: + dikKeyOut = "Dik["; + break; + + case DirectInputKeyCode.DikRbracket: + dikKeyOut = "Dik]"; + break; + + case DirectInputKeyCode.DikBackslash: + dikKeyOut = "Dik#"; + break; + + // THIRD ROW + case DirectInputKeyCode.DikSemicolon: + dikKeyOut = "Dik:"; + break; + + case DirectInputKeyCode.DikApostrophe: + dikKeyOut = "Dik'"; + break; + + // FOURTH ROW + + case DirectInputKeyCode.DikComma: + dikKeyOut = "Dik,"; + break; + + case DirectInputKeyCode.DikPeriod: + dikKeyOut = "Dik."; + break; + + case DirectInputKeyCode.DikSlash: + dikKeyOut = "Dik/"; + break; + + } + break; + + case "de-CH": + + // http://kbdlayout.info/kbdsg/shiftstates+scancodes/base + + switch (dikKey) + { + // FIRST ROW + case DirectInputKeyCode.DikGrave: + dikKeyOut = "Dik§"; + break; + + case DirectInputKeyCode.DikMinus: + dikKeyOut = "Dik'"; + break; + + case DirectInputKeyCode.DikEquals: + dikKeyOut = "Dik^"; + break; + + // SECOND ROW + case DirectInputKeyCode.DikY: + dikKeyOut = "DikZ"; + break; + + case DirectInputKeyCode.DikLbracket: + dikKeyOut = "DikÜ"; + break; + + case DirectInputKeyCode.DikRbracket: + dikKeyOut = "Dik¨"; + break; + + case DirectInputKeyCode.DikBackslash: + dikKeyOut = "Dik$"; + break; + + // THIRD ROW + case DirectInputKeyCode.DikSemicolon: + dikKeyOut = "DikÖ"; + break; + + case DirectInputKeyCode.DikApostrophe: + dikKeyOut = "DikÄ"; + break; + + // FOURTH ROW + case DirectInputKeyCode.DikZ: + dikKeyOut = "DikY"; + break; + + case DirectInputKeyCode.DikComma: + dikKeyOut = "Dik,"; + break; + + case DirectInputKeyCode.DikPeriod: + dikKeyOut = "Dik."; + break; + + case DirectInputKeyCode.DikSlash: + dikKeyOut = "Dik-"; + break; + + } + break; + + + case "es-ES": + + // http://kbdlayout.info/kbdsp/shiftstates+scancodes/base + + switch (dikKey) + { + // FIRST ROW + case DirectInputKeyCode.DikGrave: + dikKeyOut = "Dikº"; + break; + + case DirectInputKeyCode.DikMinus: + dikKeyOut = "Dik'"; + break; + + case DirectInputKeyCode.DikEquals: + dikKeyOut = "Dik¡"; + break; + + // SECOND ROW + + case DirectInputKeyCode.DikLbracket: + dikKeyOut = "Dik`"; + break; + + case DirectInputKeyCode.DikRbracket: + dikKeyOut = "Dik+"; + break; + + case DirectInputKeyCode.DikBackslash: + dikKeyOut = "Dikç"; + break; + + // THIRD ROW + case DirectInputKeyCode.DikSemicolon: + dikKeyOut = "Dikñ"; + break; + + case DirectInputKeyCode.DikApostrophe: + dikKeyOut = "Dik´"; + break; + + // FOURTH ROW + + case DirectInputKeyCode.DikComma: + dikKeyOut = "Dik,"; + break; + + case DirectInputKeyCode.DikPeriod: + dikKeyOut = "Dik."; + break; + + case DirectInputKeyCode.DikSlash: + dikKeyOut = "Dik-"; + break; + + } + break; + + case "da-DK": + + // http://kbdlayout.info/kbdda/shiftstates+scancodes/base + + switch (dikKey) + { + // FIRST ROW + case DirectInputKeyCode.DikGrave: + dikKeyOut = "Dik½"; + break; + + case DirectInputKeyCode.DikMinus: + dikKeyOut = "Dik+"; + break; + + case DirectInputKeyCode.DikEquals: + dikKeyOut = "Dik´"; + break; + + + // SECOND ROW + case DirectInputKeyCode.DikLbracket: + dikKeyOut = "DikÅ"; + break; + + case DirectInputKeyCode.DikRbracket: + dikKeyOut = "Dik¨"; + break; + + case DirectInputKeyCode.DikBackslash: + dikKeyOut = "Dik'"; + break; + + + // THIRD ROW + case DirectInputKeyCode.DikSemicolon: + dikKeyOut = "DikÆ"; + break; + + case DirectInputKeyCode.DikApostrophe: + dikKeyOut = "DikØ"; + break; + + // FOURTH ROW + + case DirectInputKeyCode.DikComma: + dikKeyOut = "Dik,"; + break; + + case DirectInputKeyCode.DikPeriod: + dikKeyOut = "Dik."; + break; + + case DirectInputKeyCode.DikSlash: + dikKeyOut = "Dik-"; + break; + + } + break; + + case "it-IT": + + // http://kbdlayout.info/kbdit/shiftstates+scancodes/base + + switch (dikKey) + { + // FIRST ROW + case DirectInputKeyCode.DikGrave: + dikKeyOut = "Dik\\"; + break; + + case DirectInputKeyCode.DikMinus: + dikKeyOut = "Dik'"; + break; + + case DirectInputKeyCode.DikEquals: + dikKeyOut = "DikÌ"; + break; + + // SECOND ROW + case DirectInputKeyCode.DikLbracket: + dikKeyOut = "DikÈ"; + break; + + case DirectInputKeyCode.DikRbracket: + dikKeyOut = "Dik+"; + break; + + case DirectInputKeyCode.DikBackslash: + dikKeyOut = "DikÙ"; + break; + + + // THIRD ROW + case DirectInputKeyCode.DikSemicolon: + dikKeyOut = "DikÒ"; + break; + + case DirectInputKeyCode.DikApostrophe: + dikKeyOut = "DikÀ"; + break; + + + // FOURTH ROW + + case DirectInputKeyCode.DikComma: + dikKeyOut = "Dik,"; + break; + + case DirectInputKeyCode.DikPeriod: + dikKeyOut = "Dik."; + break; + + case DirectInputKeyCode.DikSlash: + dikKeyOut = "Dik-"; + break; + + } + break; + + case "pt-PT": + + // http://kbdlayout.info/kbdpo/shiftstates+scancodes/base + + switch (dikKey) + { + // FIRST ROW + case DirectInputKeyCode.DikGrave: + dikKeyOut = "Dik\\"; + break; + + case DirectInputKeyCode.DikMinus: + dikKeyOut = "Dik'"; + break; + + case DirectInputKeyCode.DikEquals: + dikKeyOut = "Dik«"; + break; + + // SECOND ROW + case DirectInputKeyCode.DikLbracket: + dikKeyOut = "Dik+"; + break; + + case DirectInputKeyCode.DikRbracket: + dikKeyOut = "Dik´"; + break; + + case DirectInputKeyCode.DikBackslash: + dikKeyOut = "Dik~"; + break; + + // THIRD ROW + case DirectInputKeyCode.DikSemicolon: + dikKeyOut = "DikÇ"; + break; + + case DirectInputKeyCode.DikApostrophe: + dikKeyOut = "Dikº"; + break; + + // FOURTH ROW + + case DirectInputKeyCode.DikComma: + dikKeyOut = "Dik,"; + break; + + case DirectInputKeyCode.DikPeriod: + dikKeyOut = "Dik."; + break; + + case DirectInputKeyCode.DikSlash: + dikKeyOut = "Dik-"; + break; + + } + break; + + + case "de-DE": + // http://kbdlayout.info/kbdgr/shiftstates+scancodes/base + + switch (dikKey) + { + // FIRST ROW + case DirectInputKeyCode.DikGrave: + dikKeyOut = "Dik^"; + break; + + case DirectInputKeyCode.DikMinus: + dikKeyOut = "Dikß"; + break; + + case DirectInputKeyCode.DikEquals: + dikKeyOut = "Dik´"; + break; + + // SECOND ROW + case DirectInputKeyCode.DikY: + dikKeyOut = "DikZ"; + break; + + case DirectInputKeyCode.DikLbracket: + dikKeyOut = "DikÜ"; + break; + + case DirectInputKeyCode.DikRbracket: + dikKeyOut = "Dik+"; + break; + + case DirectInputKeyCode.DikBackslash: + dikKeyOut = "Dik#"; + break; + + // THIRD ROW + case DirectInputKeyCode.DikSemicolon: + dikKeyOut = "DikÖ"; + break; + + case DirectInputKeyCode.DikApostrophe: + dikKeyOut = "DikÄ"; + break; + + // FOURTH ROW + case DirectInputKeyCode.DikZ: + dikKeyOut = "DikY"; + break; + + case DirectInputKeyCode.DikComma: + dikKeyOut = "Dik,"; + break; + + case DirectInputKeyCode.DikPeriod: + dikKeyOut = "Dik."; + break; + + case DirectInputKeyCode.DikSlash: + dikKeyOut = "Dik-"; + break; + } + + break; + case "fr-FR": + // http://kbdlayout.info/kbdfr/shiftstates+scancodes/base + switch (dikKey) + { + // FIRST ROW + case DirectInputKeyCode.DikGrave: + dikKeyOut = "Dik²"; + break; + + case DirectInputKeyCode.Dik1: + dikKeyOut = "Dik&"; + break; + + case DirectInputKeyCode.Dik2: + dikKeyOut = "DikÉ"; + break; + + case DirectInputKeyCode.Dik3: + dikKeyOut = "Dik\""; + break; + + case DirectInputKeyCode.Dik4: + dikKeyOut = "Dik'"; + break; + + case DirectInputKeyCode.Dik5: + dikKeyOut = "Dik("; + break; + + case DirectInputKeyCode.Dik6: + dikKeyOut = "Dik-"; + break; + + case DirectInputKeyCode.Dik7: + dikKeyOut = "DikÈ"; + break; + + case DirectInputKeyCode.Dik8: + dikKeyOut = "Dik_"; + break; + + case DirectInputKeyCode.Dik9: + dikKeyOut = "DikÇ"; + break; + + case DirectInputKeyCode.Dik0: + dikKeyOut = "DikÀ"; + break; + + case DirectInputKeyCode.DikMinus: + dikKeyOut = "Dik)"; + break; + + case DirectInputKeyCode.DikEquals: + dikKeyOut = "Dik="; + break; + + // SECOND ROW + case DirectInputKeyCode.DikQ: + dikKeyOut = "DikA"; + break; + + case DirectInputKeyCode.DikW: + dikKeyOut = "DikZ"; + break; + + case DirectInputKeyCode.DikLbracket: + dikKeyOut = "Dik^"; + break; + + case DirectInputKeyCode.DikRbracket: + dikKeyOut = "Dik$"; + break; + + case DirectInputKeyCode.DikBackslash: + dikKeyOut = "Dik*"; + break; + + // THIRD ROW + case DirectInputKeyCode.DikA: + dikKeyOut = "DikQ"; + break; + + case DirectInputKeyCode.DikSemicolon: + dikKeyOut = "DikM"; + break; + + case DirectInputKeyCode.DikApostrophe: + dikKeyOut = "DikÙ"; + break; + + // FOURTH ROW + case DirectInputKeyCode.DikZ: + dikKeyOut = "DikW"; + break; + + case DirectInputKeyCode.DikM: + dikKeyOut = "Dik,"; + break; + + case DirectInputKeyCode.DikComma: + dikKeyOut = "Dik;"; + break; + + case DirectInputKeyCode.DikPeriod: + dikKeyOut = "Dik:"; + break; + + case DirectInputKeyCode.DikSlash: + dikKeyOut = "Dik!"; + break; + + } + + break; + default: + + switch (dikKey) + { + // FIRST ROW + case DirectInputKeyCode.DikGrave: + + dikKeyOut = "Dik`"; + break; + + case DirectInputKeyCode.DikMinus: + dikKeyOut = "Dik-"; + break; + + case DirectInputKeyCode.DikEquals: + dikKeyOut = "Dik="; + break; + + // SECOND ROW + + case DirectInputKeyCode.DikLbracket: + dikKeyOut = "Dik["; + break; + + case DirectInputKeyCode.DikRbracket: + dikKeyOut = "Dik]"; + break; + + case DirectInputKeyCode.DikBackslash: + dikKeyOut = "Dik\\"; + break; + + // THIRD ROW + case DirectInputKeyCode.DikSemicolon: + dikKeyOut = "Dik:"; + break; + + case DirectInputKeyCode.DikApostrophe: + dikKeyOut = "Dik'"; + break; + + // FOURTH ROW + + case DirectInputKeyCode.DikComma: + dikKeyOut = "Dik,"; + break; + + case DirectInputKeyCode.DikPeriod: + dikKeyOut = "Dik."; + break; + + case DirectInputKeyCode.DikSlash: + dikKeyOut = "Dik/"; + break; + } + + break; + } + + keyboard += "{" + dikKeyOut + "}"; + } + + return keyboard; + } private static DirectInputKeyCode FromSCKeyboardCmd(string scKey) { switch (scKey) { // handle modifiers first - case "lalt": return DirectInputKeyCode.DikLmenu; - case "ralt": return DirectInputKeyCode.DikRmenu; - case "lshift": return DirectInputKeyCode.DikLeftShift; - case "rshift": return DirectInputKeyCode.DikRightShift; - case "lctrl": return DirectInputKeyCode.DikLeftControl; - case "rctrl": return DirectInputKeyCode.DikRightControl; + case "lalt": return DirectInputKeyCode.DikLalt; + case "ralt": return DirectInputKeyCode.DikRalt; + case "lshift": return DirectInputKeyCode.DikLshift; + case "rshift": return DirectInputKeyCode.DikRshift; + case "lctrl": return DirectInputKeyCode.DikLcontrol; + case "rctrl": return DirectInputKeyCode.DikRcontrol; // function keys first case "f1": return DirectInputKeyCode.DikF1; diff --git a/starcitizen/KeyboardLayouts.cs b/starcitizen/KeyboardLayouts.cs new file mode 100644 index 0000000..93f73fd --- /dev/null +++ b/starcitizen/KeyboardLayouts.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace starcitizen +{ + // from https://gist.github.com/vurdalakov/9cea795e82109fdacb7062dcb122b42e + + + public class KeyboardLayout + { + public UInt32 Id { get; } + + public UInt16 LanguageId { get; } + public UInt16 KeyboardId { get; } + + public String LanguageName { get; } + public String KeyboardName { get; } + + internal KeyboardLayout(UInt32 id, UInt16 languageId, UInt16 keyboardId, String languageName, String keyboardName) + { + this.Id = id; + this.LanguageId = languageId; + this.KeyboardId = keyboardId; + this.LanguageName = languageName; + this.KeyboardName = keyboardName; + } + } + + public static class KeyboardLayouts + { + public static KeyboardLayout GetThreadKeyboardLayout(Int32 threadId = 0) + { + var keyboardLayoutId = (UInt32)GetKeyboardLayout((UInt32)threadId); + return CreateKeyboardLayout(keyboardLayoutId); + } + + public static KeyboardLayout GetProcessKeyboardLayout(Int32 processId = 0) + { + var threadId = GetProcessMainThreadId(processId); + return GetThreadKeyboardLayout(threadId); + } + + public static UInt32 SetThreadKeyboardLayout(UInt32 keyboardLayoutId) + { + return SetKeyboardLayout(keyboardLayoutId, 0); + } + + public static UInt32 SetProcessKeyboardLayout(UInt32 keyboardLayoutId) + { + return SetKeyboardLayout(keyboardLayoutId, KLF_SETFORPROCESS); + } + + public static KeyboardLayout[] GetSystemKeyboardLayouts() + { + var keyboardLayouts = new List(); + + var count = GetKeyboardLayoutList(0, null); + var keyboardLayoutIds = new IntPtr[count]; + GetKeyboardLayoutList(keyboardLayoutIds.Length, keyboardLayoutIds); + + foreach (var keyboardLayoutId in keyboardLayoutIds) + { + var keyboardLayout = CreateKeyboardLayout((UInt32)keyboardLayoutId); + keyboardLayouts.Add(keyboardLayout); + } + + return keyboardLayouts.ToArray(); + } + + private static Int32 GetProcessMainThreadId(Int32 processId = 0) + { + var process = 0 == processId ? Process.GetCurrentProcess() : Process.GetProcessById(processId); + return process.Threads[0].Id; + } + + private static KeyboardLayout CreateKeyboardLayout(UInt32 keyboardLayoutId) + { + var languageId = (UInt16)(keyboardLayoutId & 0xFFFF); + var keyboardId = (UInt16)(keyboardLayoutId >> 16); + + return new KeyboardLayout(keyboardLayoutId, languageId, keyboardId,"","");//, GetCultureInfoName(languageId), GetCultureInfoName(keyboardId)); + + //String GetCultureInfoName(UInt16 cultureId) + //{ + // return CultureInfo.GetCultureInfo(cultureId).DisplayName; + //} + } + + private static UInt32 SetKeyboardLayout(UInt32 keyboardLayoutId, UInt32 flags) + { + return ActivateKeyboardLayout((IntPtr)keyboardLayoutId, flags); + } + + [DllImport("user32.dll")] + private static extern IntPtr GetKeyboardLayout(UInt32 idThread); + + [DllImport("user32.dll")] + private static extern UInt32 GetKeyboardLayoutList(Int32 nBuff, IntPtr[] lpList); + + private const UInt32 KLF_SETFORPROCESS = 0x00000100; + + [DllImport("user32.dll")] + private static extern UInt32 ActivateKeyboardLayout(IntPtr hkl, UInt32 flags); + + private const uint SPI_GETDEFAULTINPUTLANG = 0x0059; + private const uint SPI_SETDEFAULTINPUTLANG = 0x005A; + private const uint SPIF_UPDATEINIFILE = 0x01; + private const uint SPIF_SENDWININICHANGE = 0x02; + private const uint DVORAK = 0xF0020409; + private const uint QWERTY = 0x04090409; + + [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] + public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref uint pvParam, uint fWinIni); + + } +} diff --git a/starcitizen/Properties/AssemblyInfo.cs b/starcitizen/Properties/AssemblyInfo.cs index f97e306..8f5a045 100644 --- a/starcitizen/Properties/AssemblyInfo.cs +++ b/starcitizen/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.3.0")] -[assembly: AssemblyFileVersion("1.0.3.0")] +[assembly: AssemblyVersion("1.0.4.0")] +[assembly: AssemblyFileVersion("1.0.4.0")] diff --git a/starcitizen/SC/DProfileReader.cs b/starcitizen/SC/DProfileReader.cs index 99e9e75..0a2d0c5 100644 --- a/starcitizen/SC/DProfileReader.cs +++ b/starcitizen/SC/DProfileReader.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Text; @@ -9,6 +10,7 @@ using BarRaider.SdTools; using p4ktest; using p4ktest.SC; +using starcitizen; using Action = System.Action; namespace SCJMapper_V2.SC @@ -419,6 +421,21 @@ public void CreateStaticHtml(string statictemplate) { try { + var keyboard = KeyboardLayouts.GetThreadKeyboardLayout(); + + CultureInfo culture; + + try + { + culture = new CultureInfo(keyboard.KeyboardId); + } + catch + { + culture = new CultureInfo("en-US"); + } + + Logger.Instance.LogMessage(TracingLevel.INFO, $"Keyboard Detected, language : {keyboard.LanguageId:X} keyboard : {keyboard.KeyboardId:X} culture : {culture.Name}"); + var dropdownHtml = new StringBuilder(); var mapsList = @@ -445,7 +462,11 @@ public void CreateStaticHtml(string statictemplate) foreach (var action in options) { - htmlline = $" "; + var keyString = CommandTools.ConvertKeyStringToLocale(action.Value.Keyboard, culture.Name); + + var key = keyString.Replace("Dik","").Replace("}{","+").Replace("}", "").Replace("{", ""); + + htmlline = $" "; dropdownHtml.AppendLine(htmlline); } diff --git a/starcitizen/manifest.json b/starcitizen/manifest.json index f398b15..65fe7b3 100644 --- a/starcitizen/manifest.json +++ b/starcitizen/manifest.json @@ -21,7 +21,7 @@ "Name": "Star Citizen", "Icon": "Images/pluginIcon", "URL": "https://github.com/mhwlng/streamdeck-starcitizen", - "Version": "1.0.3", + "Version": "1.0.4", "CodePath": "com.mhwlng.starcitizen", "Category": "Star Citizen", "CategoryIcon": "Images/categoryIcon", diff --git a/starcitizen/starcitizen.csproj b/starcitizen/starcitizen.csproj index a4ba56f..f309701 100644 --- a/starcitizen/starcitizen.csproj +++ b/starcitizen/starcitizen.csproj @@ -169,6 +169,7 @@ +