//private int CalculateSwitchingNumber(IntPtr currentLayout, IntPtr detectedLayout) //{ // var switchingNumber = Array.IndexOf(layouts, detectedLayout) - Array.IndexOf(layouts, currentLayout); // if (switchingNumber < 0) // { // switchingNumber = switchingNumber + layouts.Length; // } // return switchingNumber; //} private void RemoveSelection() { ignoreKeyPress = true; LowLevelAdapter.SendKeyPress(Keys.Space); LowLevelAdapter.SendKeyPress(Keys.Back); ignoreKeyPress = false; }
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"); }
private void PressKeys(List <Keys> keys) { foreach (var key in keys) { //Debug.Write(key); if (key != Keys.None) { LowLevelAdapter.SendKeyPress(key, (key & Keys.Shift) != Keys.None); Thread.Sleep(10); } } }
private void ConvertLast(string lang) { Debug.WriteLine($"ConvertLast to {lang}..."); var fnKeys = LowLevelAdapter.ReleasePressedFnKeys(); // Fix for apps with autocompletion (i.e. omnibox in Google Chrome browser) RemoveSelection(); ignoreKeyPress = true; // Remove last word var backspaceCount = autoSwitchingIsGoing ? (currentSelection.Count - 1) : currentSelection.Count; var backspaces = Enumerable.Repeat <Keys>(Keys.Back, backspaceCount); foreach (var backspace in backspaces) { Thread.Sleep(settings.SwitchDelay); LowLevelAdapter.SendKeyPress(backspace, false); } //Change layout if (lang == "next") { LowLevelAdapter.SetNextKeyboardLayout(); } else { LowLevelAdapter.SetKeyboadLayout(langToLayout[lang]); } // Type last word in new layout foreach (var data in currentSelection) { Thread.Sleep(settings.SwitchDelay); LowLevelAdapter.SendKeyPress(data.KeyCode, data.Shift); } LowLevelAdapter.PressPressedFnKeys(fnKeys); ignoreKeyPress = false; }
private void ConvertSelection() { ignoreKeyPress = true; LowLevelAdapter.BackupClipboard(); var fnKeys = LowLevelAdapter.ReleasePressedFnKeys(); LowLevelAdapter.SendCopy(); var selection = Clipboard.GetText(); LowLevelAdapter.RestoreClipboard(); if (String.IsNullOrEmpty(selection)) { LowLevelAdapter.PressPressedFnKeys(fnKeys); return; } var keys = new List <Keys>(selection.Length); for (var i = 0; i < selection.Length; i++) { keys.Add(LowLevelAdapter.ToKey(selection[i])); } LowLevelAdapter.SetNextKeyboardLayout(); ignoreKeyPress = true; foreach (var key in keys) { Debug.Write(key); if (key != Keys.None) { LowLevelAdapter.SendKeyPress(key, (key & Keys.Shift) != Keys.None); } } Debug.WriteLine(""); LowLevelAdapter.PressPressedFnKeys(fnKeys); ignoreKeyPress = false; }