private IEnumerable <LayoutName> GetAvailableKeyboardNames(InputLanguage inputLanguage) { IEnumTfInputProcessorProfiles profilesEnumerator; try { profilesEnumerator = ProfileManager.EnumProfiles((short)inputLanguage.Culture.KeyboardLayoutId); } catch (Exception e) { Debug.WriteLine($"Error looking up keyboards for language {inputLanguage.Culture.Name} - {(short)inputLanguage.Culture.KeyboardLayoutId}"); yield break; } TfInputProcessorProfile[] profiles = new TfInputProcessorProfile[1]; bool returnedLanguage = false; while (profilesEnumerator.Next(1, profiles) == 1) { // We only deal with keyboards; skip other input methods if (profiles[0].CatId != Guids.Consts.TfcatTipKeyboard) { continue; } if ((profiles[0].Flags & TfIppFlags.Enabled) == 0) { continue; } if (profiles[0].ProfileType == TfProfileType.Illegal) { continue; } LayoutName layoutName; if (profiles[0].Hkl == IntPtr.Zero) { returnedLanguage = true; layoutName = new LayoutName(inputLanguage.LayoutName, ProcessorProfiles.GetLanguageProfileDescription(ref profiles[0].ClsId, profiles[0].LangId, ref profiles[0].GuidProfile), profiles[0]); yield return(layoutName); } else { layoutName = WinKeyboardUtils.GetLayoutNameEx(profiles[0].Hkl); if (layoutName.Name != string.Empty) { layoutName.Profile = profiles[0]; returnedLanguage = true; yield return(layoutName); } } } if (!returnedLanguage) { yield return(new LayoutName(inputLanguage.LayoutName, inputLanguage.Culture.DisplayName)); } }
/// <summary> /// Creates and returns a keyboard definition object based on the ID. /// Note that this method is used when we do NOT have a matching available keyboard. /// Therefore we can presume that the created one is NOT available. /// </summary> public KeyboardDescription CreateKeyboardDefinition(string id) { string layout, locale; KeyboardController.GetLayoutAndLocaleFromLanguageId(id, out layout, out locale); string cultureName; var inputLanguage = WinKeyboardUtils.GetInputLanguage(locale, layout, out cultureName); return(new WinKeyboardDescription(id, GetDisplayName(layout, cultureName), layout, cultureName, false, inputLanguage, this, default(TfInputProcessorProfile))); }
/// <summary> /// Creates and returns a keyboard definition object based on the ID. /// Note that this method is used when we do NOT have a matching available keyboard. /// Therefore we can presume that the created one is NOT available. /// </summary> public KeyboardDescription CreateKeyboardDefinition(string id) { CheckDisposed(); switch (InstalledKeymanVersion) { case KeymanVersion.Keyman10: string layout, locale; KeyboardController.GetLayoutAndLocaleFromLanguageId(id, out layout, out locale); string cultureName; var inputLanguage = WinKeyboardUtils.GetInputLanguage(locale, layout, out cultureName); return(new KeymanKeyboardDescription(id, false, this, false) { InputLanguage = inputLanguage }); default: return(new KeymanKeyboardDescription(id, false, this, false)); } }
private IEnumerable <LayoutName> GetAvailableKeyboardNames(InputLanguage inputLanguage) { IEnumTfInputProcessorProfiles profilesEnumerator; string cultureName; var culture = GetCultureInfoFromInputLanguage(inputLanguage, out cultureName); if (cultureName == UnknownLanguage) { Debug.WriteLine($"Error looking up keyboards with layout {inputLanguage.LayoutName} - invalid culture"); yield break; } try { profilesEnumerator = ProfileManager.EnumProfiles((short)culture.KeyboardLayoutId); } catch { Debug.WriteLine($"Error looking up keyboards for language {culture.Name} - {(short)culture.KeyboardLayoutId}"); yield break; } TfInputProcessorProfile[] profiles = new TfInputProcessorProfile[1]; bool returnedLanguage = false; while (profilesEnumerator.Next(1, profiles) == 1) { // We only deal with keyboards; skip other input methods if (profiles[0].CatId != Guids.Consts.TfcatTipKeyboard) { continue; } if ((profiles[0].Flags & TfIppFlags.Enabled) == 0) { continue; } if (profiles[0].ProfileType == TfProfileType.Illegal) { continue; } LayoutName layoutName; if (profiles[0].Hkl == IntPtr.Zero) { try { layoutName = new LayoutName(inputLanguage.LayoutName, ProcessorProfiles.GetLanguageProfileDescription(ref profiles[0].ClsId, profiles[0].LangId, ref profiles[0].GuidProfile), profiles[0]); } catch { // this exception has happened in testing, doesn't seem to be anything we can do // except just ignore this keyboard continue; } returnedLanguage = true; yield return(layoutName); } else { layoutName = WinKeyboardUtils.GetLayoutNameEx(profiles[0].Hkl); if (layoutName.Name != string.Empty) { layoutName.Profile = profiles[0]; returnedLanguage = true; yield return(layoutName); } } } if (!returnedLanguage) { yield return(new LayoutName(inputLanguage.LayoutName, culture.DisplayName)); } }