Get Keyboard layout

Byak@

Active Member
Licensed User
i'm found interesting code for C#.how adapt it for basic?
B4X:
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;
}
}
}
 

Cableguy

Expert
Licensed User
Longtime User
This seems to be a complete .cs file...
Wich means that you could try to add it to a SharpDevelop Class project and compile it, if successfull, then you have a working dll...
I may try it latter in the day, as I am now going out...
 

Byak@

Active Member
Licensed User
Thanks Cableguy
and do it without creating a lib in B4p isn't possible?
 

Cableguy

Expert
Licensed User
Longtime User
Thanks Cableguy
and do it without creating a lib in B4p isn't possible?

I don't thing its possible as this seems to be a wraper of some "user32.dll" properties...
Anyway here's the dll:

PS:
Please note that this is NOT a zip file, I only added the .zip to the dll, so only need to delete the ".zip" from the name
 

Attachments

  • CultureInfo.dll.zip
    6 KB · Views: 260

Byak@

Active Member
Licensed User
i'm not found a "new" method =(
Cableguy please correct it
 

Byak@

Active Member
Licensed User
UP!
Can anyone help with it?
 

Byak@

Active Member
Licensed User
Big thanks!it's work)
what about do it for device? and please give source of this lib for embed
 
Top