1
1
using System ;
2
+ using System . Linq ;
2
3
using System . Runtime . InteropServices ;
3
- using System . Text ;
4
4
5
5
namespace Flow . Launcher . Helper ;
6
6
@@ -20,17 +20,15 @@ public static class KeyboardLayoutHelper
20
20
[ DllImport ( "user32.dll" ) ]
21
21
private static extern int GetKeyboardLayoutList ( int nBuff , [ Out ] IntPtr [ ] lpList ) ;
22
22
23
- [ DllImport ( "kernel32.dll" ) ]
24
- private static extern int GetLocaleInfoA ( uint Locale , uint LCType , StringBuilder lpLCData , int cchData ) ;
25
-
26
23
[ DllImport ( "user32.dll" ) ]
27
24
private static extern IntPtr GetForegroundWindow ( ) ;
28
25
29
- // Used to get the language name of the keyboard layout
30
- private const uint LOCALE_SLANGUAGE = 0x00000002 ;
31
-
32
- // The string to search for in the language name of a keyboard layout
33
- private const string LAYOUT_ENGLISH_SEARCH = "english" ;
26
+ // https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/70feba9f-294e-491e-b6eb-56532684c37f
27
+ private static readonly uint [ ] EnglishLanguageIds =
28
+ {
29
+ 0x0009 , 0x0409 , 0x0809 , 0x0C09 , 0x1000 , 0x1009 , 0x1409 , 0x1809 , 0x1C09 , 0x2009 , 0x2409 , 0x2809 , 0x2C09 ,
30
+ 0x3009 , 0x3409 , 0x3C09 , 0x4009 , 0x4409 , 0x4809 , 0x4C09 ,
31
+ } ;
34
32
35
33
private static IntPtr FindEnglishKeyboardLayout ( )
36
34
{
@@ -48,13 +46,8 @@ private static IntPtr FindEnglishKeyboardLayout()
48
46
// The lower word contains the language identifier
49
47
var langId = ( uint ) layout . ToInt32 ( ) & 0xFFFF ;
50
48
51
- // Get language name for the layout
52
- var sb = new StringBuilder ( 256 ) ;
53
- GetLocaleInfoA ( langId , LOCALE_SLANGUAGE , sb , sb . Capacity ) ;
54
- var langName = sb . ToString ( ) . ToLowerInvariant ( ) ;
55
-
56
49
// Check if it's an English layout
57
- if ( langName . Contains ( LAYOUT_ENGLISH_SEARCH ) )
50
+ if ( EnglishLanguageIds . Contains ( langId ) )
58
51
{
59
52
return layout ;
60
53
}
0 commit comments