Author: Lou Adler
When my application starts, I need to switch the keyboard language to Greek.
Currently I use the statement ActivateKeyboardlayout(0, 0). When I need to switch
to English (when the application terminates) I execute the same statement one more
time. This works fine, but only if the language before the application's execution
is English. So, before the call of the statement, I need to know if the language is
Greek or English. How can do this?
Answer:
I usually use the following cycle:
1 { ... }2 GetKeyboardLayoutName(@t);
3 y := string(t);
4 repeat5 ActivateKeyboardLayout(HKL_NEXT, 0);
6 GetKeyboardLayoutName(@t);
7 x := string(t);
8 until9 ((x = y) or (x = '00000405'));
10 { ... }
Using this, the English keyboard will give the KeyboardLayoutName '00000409' and
the Greek one the '000000408'. These are standard language identifiers. They're the
same on any Windows machine.
To display the information, you could use this little trick:
11 { ... }12 var13 kbd: array[0..2] of Char;
14 begin15 GetLocaleInfo(loWord(GetKeyboardLayout(0)), LOCALE_SENGLANGUAGE, kbd, 2);
16 Form1.Caption := kbd;
17 { ... }