简体   繁体   English

在 C# 的语言中切换多种键盘类型

[英]Switch between multiple keyboard types within a language in C#

I am using Hindi Indic Input 3 Language Pack for Hindi language.我正在为印地语使用印地语 Indic Input 3 语言包。 I need to provide multiple layout options for this language but when I check the installed language types it shows same Layout Id for all the layouts within this language pack.我需要为此语言提供多个布局选项,但是当我检查已安装的语言类型时,它会为此语言包中的所有布局显示相同的布局 ID。 My objective is to allow users to switch between Mangal - CBI and Mangal - GAIL input from my WinForms application.我的目标是允许用户在我的 WinForms 应用程序的 Mangal - CBI 和 Mangal - GAIL 输入之间切换。 Below is the code:下面是代码:

void ChangeCulture(string culture)
{
    original = InputLanguage.CurrentInputLanguage;
    var _culture = System.Globalization.CultureInfo.GetCultureInfo(culture);
    var _language = InputLanguage.FromCulture(_culture);
    if (InputLanguage.InstalledInputLanguages.IndexOf(_language) >= 0)
        InputLanguage.CurrentInputLanguage = _language;
    else
        InputLanguage.CurrentInputLanguage = InputLanguage.DefaultInputLanguage;
}

I also used this native method for changing the keyboard layout using the layout id.我还使用这种本机方法使用布局 ID 更改键盘布局。 But the problem is the layout id is same for all Hindi Indic Input 3 layout types .但问题是所有 Hindi Indic Input 3 布局类型的布局 id 都是相同的

[DllImport("user32.dll")]
private static extern IntPtr LoadKeyboardLayout(string pwszKLID, uint Flags);
LoadKeyboardLayout("hi-IN", 0xf0c00439);

I am unable to find any documentation on this language pack.我找不到有关此语言包的任何文档。 Below is how it is selected from language bar.以下是从语言栏中选择它的方式。 I need to select these two GAIL and CBI types from C# code.我需要 select 这两种 GAIL 和 CBI 类型来自 C# 代码。 Please help.请帮忙。

在此处输入图像描述

Looks like you need to check an input locale identifier (formerly called the keyboard layout, HKL) instead of InputLanguage.看起来您需要检查input locale identifier (以前称为键盘布局,HKL)而不是 InputLanguage。 That's why your language stays the same (Hindi) when you have different layouts.这就是为什么当你有不同的布局时你的语言保持不变(印地语)。 You don't need the pack docs because installed 'language' is a part of the system.您不需要打包文档,因为安装的“语言”是系统的一部分。

OS Windows has a wider definition for 'InputLanguage' than just a 'keyboard layout'. OS Windows 对“InputLanguage”的定义比“键盘布局”更广泛。 It has ALL input channels, including 'speech-to-text', an Input Method Editor (IME).它具有所有输入通道,包括“语音到文本”、输入法编辑器 (IME)。 When the keyboard layout sets, it sets InputLanguage.CurrentInputLanguage also.当键盘布局设置时,它也会设置InputLanguage.CurrentInputLanguage

So, yes, user32.dll is the right way to call Window's C++ functions:所以,是的, user32.dll是调用 Window 的 C++ 函数的正确方法:

HKL GetKeyboardLayout(
  [in] DWORD idThread
);
HKL ActivateKeyboardLayout(
  [in] HKL  hkl,
  [in] UINT Flags
);

Just try other functions from this DLL.试试这个 DLL 的其他功能。 Such as GetKeyboardLayout (get current layout for a thread), GetKeyboardLayoutList (get all system layouts), ActivateKeyboardLayout (set HKL as active).GetKeyboardLayout (获取线程的当前布局)、 GetKeyboardLayoutList (获取所有系统布局)、 ActivateKeyboardLayout (设置HKL为活动)。

Please, check the gist below from https://github.com/vurdalakov to play with layouts, not languages: https://gist.github.com/vurdalakov/9cea795e82109fdacb7062dcb122b42e Please, check the gist below from https://github.com/vurdalakov to play with layouts, not languages: https://gist.github.com/vurdalakov/9cea795e82109fdacb7062dcb122b42e

Hope, this will help.希望,这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM