Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
      }
   }
}


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]
Posted
Updated 27-Jun-11 9:16am
v2
Comments
sunder.tinwar 27-Jun-11 15:07pm    
I perhaps want to create an object which will load setting of current keyboard layout of current culture and get all keys text.

Next time I need an event also. If culture change my application should get notification and I will load my keyboard settings again.
OriginalGriff 27-Jun-11 15:18pm    
Urgency deleted: It may be urgent to you, but it isn't to us. All that your stressing the urgency does is to make us think you have left it too late, and want us to do it for you. This annoys some people, and can slow a response.

When you paste a code fragment, a few things are a good idea:
1) Do not delete the original indentation - it makes it hard to read.
2) Use a Code block - it both preserves the indentation in the output, and applies syntax coloring.
3) Make it relevant. Posting your whole class is a paste of your time, and ours, and reduces your chances of a sensible answer.

1 solution

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
 
Share this answer
 
Comments
sunder.tinwar 28-Jun-11 0:23am    
I only suggested this link in my last post. But there is not information provided about keyboard layouts.
ankitjoshi24 28-Jun-11 10:14am    
Ohk. I had no idea that you had already been through this website.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900