1-) C# RMOS - ChangeLanguage
kaynak : https://stackoverflow.com/questions/37291533/change-keyboard-layout-from-c-sharp-code-with-net-4-5-2/51305590
kod : https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-vista/cc766503(v=ws.10)
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace AnketKiosk.Language
{
public class Languages
{
[DllImport("user32.dll",
CallingConvention = CallingConvention.StdCall,
CharSet = CharSet.Unicode,
EntryPoint = "LoadKeyboardLayout",
SetLastError = true,
ThrowOnUnmappableChar = false)]
static extern uint LoadKeyboardLayout(
StringBuilder pwszKLID,
uint flags);
[DllImport("user32.dll",
CallingConvention = CallingConvention.StdCall,
CharSet = CharSet.Unicode,
EntryPoint = "GetKeyboardLayout",
SetLastError = true,
ThrowOnUnmappableChar = false)]
static extern uint GetKeyboardLayout(
uint idThread);
[DllImport("user32.dll",
CallingConvention = CallingConvention.StdCall,
CharSet = CharSet.Unicode,
EntryPoint = "ActivateKeyboardLayout",
SetLastError = true,
ThrowOnUnmappableChar = false)]
static extern uint ActivateKeyboardLayout(
uint hkl,
uint Flags);
static class KeyboardLayoutFlags
{
public const uint KLF_ACTIVATE = 0x00000001;
public const uint KLF_SETFORPROCESS = 0x00000100;
}
internal sealed class KeyboardLayout
{
private readonly uint hkl;
private KeyboardLayout(CultureInfo cultureInfo)
{
string layoutName = cultureInfo.LCID.ToString("x8");
var pwszKlid = new StringBuilder(layoutName);
this.hkl = LoadKeyboardLayout(pwszKlid, KeyboardLayoutFlags.KLF_ACTIVATE);
}
private KeyboardLayout(uint hkl)
{
this.hkl = hkl;
}
public uint Handle
{
get
{
return this.hkl;
}
}
public static KeyboardLayout GetCurrent()
{
uint hkl = GetKeyboardLayout((uint)Thread.CurrentThread.ManagedThreadId);
return new KeyboardLayout(hkl);
}
public static KeyboardLayout Load(CultureInfo culture)
{
return new KeyboardLayout(culture);
}
public void Activate()
{
ActivateKeyboardLayout(this.hkl, KeyboardLayoutFlags.KLF_SETFORPROCESS);
}
}
public class KeyboardLayoutScope : IDisposable
{
private readonly KeyboardLayout currentLayout;
public KeyboardLayoutScope(CultureInfo culture)
{
this.currentLayout = KeyboardLayout.GetCurrent();
var layout = KeyboardLayout.Load(culture);
layout.Activate();
}
public void Dispose()
{
this.currentLayout.Activate();
}
}
}
}
2-) KULLANIMI
KeyboardLayoutScope ss = new KeyboardLayoutScope(CultureInfo.CreateSpecificCulture("tr-TR"));
//KeyboardLayoutScope ss = new KeyboardLayoutScope(CultureInfo.CreateSpecificCulture("en-US"));
//KeyboardLayoutScope ss = new KeyboardLayoutScope(CultureInfo.CreateSpecificCulture("de-DE"));
//KeyboardLayoutScope ss = new KeyboardLayoutScope(CultureInfo.CreateSpecificCulture("ru-RU"));
//KeyboardLayoutScope aa = new KeyboardLayoutScope(CultureInfo.GetCultureInfo(1049));