c#检索OS文化的键盘布局 [英] c# retrieve keyboard layout of OS culture

查看:71
本文介绍了c#检索OS文化的键盘布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试将我的应用程序转换为支持所有OS语言的多语言应用程序.

现在,例如,如果我将键盘布局从控制面板更改为阿拉伯语,则我的应用程序应开始使用阿拉伯语和其他语言(如西班牙语等).

因此,想法是使用阿拉伯语来获取键盘布局,获取该键盘中的所有键文本并在我的应用程序中使用.

我发现了很多代码,但是它们都不起作用.
http://www.codeproject.com/KB/winsdk/RightKeyboard.aspx

这似乎很有希望,但是我如何根据自己的要求进行更改.我现在有了键盘ID,如何获取该键盘ID中的所有键文本.

Hi All,

I am trying to convert my application to multilingual application which will support all OS language.

Now for example if I change my keyboard layout from control panel to arabic my application should start working for arabic and for other langauge like spanish and so on.

So the idea is to get the keyboard layout in arabic langauge, get all keys text in that keyboard and use in my application.

I found lot of code but none of them is working.
http://www.codeproject.com/KB/winsdk/RightKeyboard.aspx

This seems bit promising but how can I change it according to my requirement. I got keyboard id now how can I get all keys text in that keyboard id.

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Globalization;
using System.Windows.Forms;
namespace HotKey
{
   public static class CurrentCultureInfo
   {
   #region Fields & Properties
   private static int lpdwProcessId;
   private static InputLanguageCollection installedInputLanguages = InputLanguage.InstalledInputLanguages;
   private static CultureInfo currentInputLanguage;
   public static string InputLangTwoLetterISOLanguageName
      {
      get { return CurrentCultureInfo.currentInputLanguage.TwoLetterISOLanguageName; }
      }
   public static string InputLangThreeLetterWindowsLanguageName
      {
      get { return CurrentCultureInfo.currentInputLanguage.ThreeLetterWindowsLanguageName; }
      }
   public static string InputLangThreeLetterISOLanguageName
      {
      get { return CurrentCultureInfo.currentInputLanguage.ThreeLetterISOLanguageName; }
      }
   public static string InputLangNativeName
      {
      get { return CurrentCultureInfo.currentInputLanguage.NativeName; }
      }
   public static string InputLangName
      {
      get { return CurrentCultureInfo.currentInputLanguage.Name; }
      }
   public static int InputLangLCID
      {
      get { return CurrentCultureInfo.currentInputLanguage.LCID; }
      }
   public static int InputLangKeyboardLayoutId
      {
      get { return CurrentCultureInfo.currentInputLanguage.KeyboardLayoutId; }
      }
   public static string InputLangEnglishName
      {
      get { return CurrentCultureInfo.currentInputLanguage.EnglishName; }
      }
   public static string InputLangDisplayName
      {
      get { return CurrentCultureInfo.currentInputLanguage.DisplayName; }
      }
   #endregion
   [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
   private static extern IntPtr GetForegroundWindow();
   [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
   private static extern int GetWindowThreadProcessId(IntPtr handleWindow, out int lpdwProcessID);
   [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
   private static extern IntPtr GetKeyboardLayout(int WindowsThreadProcessID);
   public static int GetKeyboardLayoutIdAtTime()
      {
      IntPtr hWnd = GetForegroundWindow();
      int WinThreadProcId = GetWindowThreadProcessId(hWnd, out lpdwProcessId);
      IntPtr KeybLayout = GetKeyboardLayout(WinThreadProcId);
      for (int i = 0; i < installedInputLanguages.Count; i++)
         {
         if (KeybLayout == installedInputLanguages[i].Handle) currentInputLanguage = installedInputLanguages[i].Culture;
         }
      return currentInputLanguage.KeyboardLayoutId;
      }
   }
}



该教程代码如何工作,似乎很有希望.
http://www.csharphelp.com/2007/01/keyboardlayout-and-language-selector/

请帮忙


非常感谢



[edit]已添加代码块,添加了缩进,禁用了忽略HTML ..."选项,并删除了紧急性-OriginalGriff [/edit]



How this tutorial code can work, its seems promising.
http://www.csharphelp.com/2007/01/keyboardlayout-and-language-selector/

Please help


Thanks a lot



[edit]Code block added, indentation added, "Ignore HTML..." option disabled, urgency deleted - OriginalGriff[/edit]

推荐答案

可能是以下链接会有所帮助.

http://msdn.microsoft.com/en-us/magazine/cc163824.aspx [ ^ ]

我不确定这可能对您有多大帮助,但想将其放在此处以便您可以轻松地进行操作.

-
AJ
May be the following link would be of some help.

http://msdn.microsoft.com/en-us/magazine/cc163824.aspx[^]

I am not sure how helpful this may be to you but thought of putting it here so that you can just go through it.

--
AJ


这篇关于c#检索OS文化的键盘布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆