11using System ;
2+ using System . Linq ;
23using System . Runtime . InteropServices ;
3- using System . Text ;
44
55namespace Flow . Launcher . Helper ;
66
@@ -20,17 +20,15 @@ public static class KeyboardLayoutHelper
2020 [ DllImport ( "user32.dll" ) ]
2121 private static extern int GetKeyboardLayoutList ( int nBuff , [ Out ] IntPtr [ ] lpList ) ;
2222
23- [ DllImport ( "kernel32.dll" ) ]
24- private static extern int GetLocaleInfoA ( uint Locale , uint LCType , StringBuilder lpLCData , int cchData ) ;
25-
2623 [ DllImport ( "user32.dll" ) ]
2724 private static extern IntPtr GetForegroundWindow ( ) ;
2825
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+ } ;
3432
3533 private static IntPtr FindEnglishKeyboardLayout ( )
3634 {
@@ -48,13 +46,8 @@ private static IntPtr FindEnglishKeyboardLayout()
4846 // The lower word contains the language identifier
4947 var langId = ( uint ) layout . ToInt32 ( ) & 0xFFFF ;
5048
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-
5649 // Check if it's an English layout
57- if ( langName . Contains ( LAYOUT_ENGLISH_SEARCH ) )
50+ if ( EnglishLanguageIds . Contains ( langId ) )
5851 {
5952 return layout ;
6053 }
0 commit comments