static void AssertAllKeyboardsValid(IKeyboardHost host, params string[] layoutXmls)
 {
     try
     {
         foreach (var layoutXml in layoutXmls)
         {
             var layout = KeyboardLayout.Load(layoutXml);
             layout.AssertValid(host);
         }
     }
     catch (Exception ex)
     {
         Debug.Fail(ex.Message);
     }
 }
Exemplo n.º 2
0
        public void GatherKeystrokes()
        {
            _keystrokes.Clear();

            foreach (KeyboardLayoutName name in Enum.GetValues(typeof(KeyboardLayoutName)))
            {
                var xml = KeyboardPanel.GetKeyboardLayoutXml(name);
                if (xml != null)
                {
                    var layout = KeyboardLayout.Load(xml);

                    Walk(layout);
                }
            }

            KeystrokeCasesTest.AssertEverything(_keystrokes);
        }
Exemplo n.º 3
0
        public async void ChangeKeyboardInputLanguage()
        {
            try
            {
                var totalLanaguages = InputLanguage.InstalledInputLanguages.Count;
                for (int idx = 0; idx < totalLanaguages; idx++)
                {
                    if (InputLanguage.InstalledInputLanguages[idx].Culture.LCID == languageInput?.LCID)
                    {
                        CultureInfo culture = null;
                        int nextLanguage = idx;
                        do
                        {
                            nextLanguage = (idx + 1) % totalLanaguages;
                            culture = InputLanguage.InstalledInputLanguages[nextLanguage].Culture;
                        } while (culture != null && culture.LCID == InputLanguage.InstalledInputLanguages[idx].Culture.LCID && nextLanguage != idx);

                        if (culture == null)
                        {
                            Logger.Instance.LogMessage(TracingLevel.ERROR, $"{this.GetType()} ChangeKeyboardInputLanguage: Could not find next language culture");
                            return;
                        }
                        
                        if (culture.LCID == InputLanguage.InstalledInputLanguages[idx].Culture.LCID)
                        {

                            Logger.Instance.LogMessage(TracingLevel.ERROR, $"{this.GetType()} ChangeKeyboardInputLanguage could not find different language");
                            return;
                        }

                        (await KeyboardLayout.Load(culture)).Activate();
                        return;
                    }
                }

            }
            catch (Exception ex)
            {

                Logger.Instance.LogMessage(TracingLevel.ERROR, $"{this.GetType()} ChangeKeyboardInputLanguage Exception {ex}");
            }
        }
        static KeyboardLayout GetKeyboardLayout(IKeyboardHost host, KeyboardLayoutName name)
        {
            var layoutXml = GetKeyboardLayoutXml(name);

            if (layoutXml == null)
            {
                try
                {
                    var myDocuments = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                    var fileName    = "KeyboardLayout.xml";
                    var path        = Path.Combine(myDocuments, fileName);

                    layoutXml = File.ReadAllText(path);
                }
                catch (Exception ex)
                {
                    host.ShowException("Error loading custom keyboard", ex);

                    layoutXml = GetKeyboardLayoutXml(KeyboardLayoutName.Default);
                }
            }

            KeyboardLayout layout;

            try
            {
                layout = KeyboardLayout.Load(layoutXml);
            }
            catch (Exception ex)
            {
                host.ShowException("Error parsing custom keyboard", ex);

                layoutXml = GetKeyboardLayoutXml(KeyboardLayoutName.Default);
                layout    = KeyboardLayout.Load(layoutXml);
            }

            return(layout);
        }