-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathKeyboardLayoutHelper.cs
More file actions
33 lines (28 loc) · 1.09 KB
/
KeyboardLayoutHelper.cs
File metadata and controls
33 lines (28 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using ManagedShell.Common.Structs;
using ManagedShell.Interop;
using System.Collections.Generic;
using System.Linq;
using System;
namespace ManagedShell.Common.Helpers
{
public static class KeyboardLayoutHelper
{
public static KeyboardLayout GetKeyboardLayout()
{
uint threadId = NativeMethods.GetWindowThreadProcessId(NativeMethods.GetForegroundWindow(), out _);
var layout = NativeMethods.GetKeyboardLayout(threadId);
return new KeyboardLayout(layout);
}
public static List<KeyboardLayout> GetKeyboardLayoutList()
{
var size = NativeMethods.GetKeyboardLayoutList(0, null);
var result = new long[size];
NativeMethods.GetKeyboardLayoutList(size, result);
return result.Select(x => new KeyboardLayout((int)x)).ToList();
}
public static bool SetKeyboardLayout(int layoutId)
{
return NativeMethods.PostMessage(NativeMethods.GetForegroundWindow(), (int)NativeMethods.WM.INPUTLANGCHANGEREQUEST, IntPtr.Zero, new IntPtr(layoutId));
}
}
}