Beispiel #1
0
        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");
        }
Beispiel #2
0
        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;
        }