public void AutoSwitchingTest() { var path = AppDomain.CurrentDomain.BaseDirectory; Debug.WriteLine($"Current path is {path}"); var app = Process.Start($"{path}\\..\\Release\\AutoMova.exe"); app.WaitForInputIdle(); var notepad = Process.Start("notepad.exe"); notepad.WaitForInputIdle(); var layouts = LowLevelAdapter.GetLayoutList(); var inputLangCollection = InputLanguage.InstalledInputLanguages; InputLanguage[] langs = new InputLanguage[layouts.Length]; inputLangCollection.CopyTo(langs, 0); Dictionary <IntPtr, string[]> testStrings = new Dictionary <IntPtr, string[]>(); foreach (var lang in langs) { testStrings.Add(layouts[Array.IndexOf(langs, lang)], System.IO.File.ReadAllLines($"{path}\\..\\..\\Test\\data\\{lang.Culture.Name.Substring(0,2)}.txt")); } string expectedString = ""; List <List <Keys> > testKeyCodes = new List <List <Keys> >(); foreach (var layout in testStrings.Keys) { foreach (var str in testStrings[layout]) { expectedString += (str + " "); PressKeys(StringToKeys(str, layout)); } } LowLevelAdapter.SendSelectAll(); LowLevelAdapter.SendCopy(); LowLevelAdapter.SendKeyPress(Keys.Delete); notepad.CloseMainWindow(); notepad.Close(); app.Kill(); var actualString = Clipboard.GetText(); var expectedWords = expectedString.Split(' '); var actualWords = actualString.Split(' '); for (int i = 0; i < expectedWords.Length; i++) { if (expectedWords[i] != actualWords[i]) { Debug.WriteLine($"{expectedWords[i]} -> {actualWords[i]}"); } } Assert.AreEqual(expectedWords, actualWords, "Auto switching error"); }
protected override void OnHandleCreated(EventArgs e) { var layouts = LowLevelAdapter.GetLayoutList(); var inputLangCollection = InputLanguage.InstalledInputLanguages; InputLanguage[] inputLangs = new InputLanguage[layouts.Length]; inputLangCollection.CopyTo(inputLangs, 0); foreach (var lang in inputLangs) { textBoxDebug.AppendText(lang.Culture.Name + ' ' + (layouts[Array.IndexOf(inputLangs, lang)]).ToString("x8") + "\n"); } }
public SwitcherCore(ISettings settings) { this.settings = settings; kbdHook = new KeyboardHook(); kbdHook.KeyboardEvent += ProcessKeyPress; mouseHook = new MouseHook(); mouseHook.MouseEvent += ProcessMousePress; readyToSwitch = false; autoSwitchingIsGoing = false; manualSwitchingIsGoing = false; ignoreKeyPress = false; var layouts = LowLevelAdapter.GetLayoutList(); var inputLangCollection = InputLanguage.InstalledInputLanguages; InputLanguage[] inputLangs = new InputLanguage[layouts.Length]; inputLangCollection.CopyTo(inputLangs, 0); foreach (var lang in inputLangs) { Debug.WriteLine(lang.Culture.Name); Debug.WriteLine((layouts[Array.IndexOf(inputLangs, lang)]).ToString("x8")); if (!langToLayout.ContainsKey(lang.Culture.Name)) { langToLayout.Add(lang.Culture.Name, (uint)(layouts[Array.IndexOf(inputLangs, lang)])); langToIntPtr.Add(lang.Culture.Name, layouts[Array.IndexOf(inputLangs, lang)]); } layoutToLang.Add(layouts[Array.IndexOf(inputLangs, lang)], lang.Culture.Name); } var langs = langToLayout.Keys.ToArray(); foreach (var lang in langs) { lastWord.Add(lang, ""); langStatistics.Add(lang, 0); } layoutDetector = new LayoutDetector(langs); }