Как yзнать текущую (Ru/En) pаскладкy клавиатypы?
// Способ первый
procedure TForm1.Button1Click(Sender: TObject);
var
AklName: PWideChar;
begin
GetMem(AklName, SizeOf(Char) * 3);
GetLocaleInfo(LoWord(GetKeyboardLayout(0)),
LOCALE_SABBREVLANGNAME, AklName,
SizeOf(AklName));
ShowMessage(AklName);
FreeMem(AklName);
end;
// Способ второй
procedure TForm1.Button1Click(Sender: TObject);
var
AklName: PWideChar;
begin
GetMem(AklName, SizeOf(Char) * 3);
GetLocaleInfo(LoWord(GetKeyboardLayout(0)),
LOCALE_SISO639LANGNAME, AklName,
SizeOf(AklName));
ShowMessage(AklName);
FreeMem(AklName);
end;
// Способ третий
function GetCurrentInputLanguage: string;
var
LocaleID: cardinal;
Size: Integer;
Success: Boolean;
Layout: HKL;
SubLanguage, PrimaryLanguage: string;
begin
Success := False;
Layout := GetKeyboardLayout(0);
LocaleID := LoWord(Layout);
Size := GetLocaleInfo(LocaleID, LOCALE_SISO639LANGNAME, nil, 0);
SetLength(PrimaryLanguage, Size);
if GetLocaleInfo(LocaleID, LOCALE_SISO639LANGNAME, @PrimaryLanguage[1], Size) <> 0 then
begin
SetLength(PrimaryLanguage, Size - 1);
Size := GetLocaleInfo(LocaleID, LOCALE_SISO3166CTRYNAME, nil, 0);
SetLength(SubLanguage, Size);
if GetLocaleInfo(LocaleID, LOCALE_SISO3166CTRYNAME, @SubLanguage[1], Size) <> 0 then
begin
SetLength(SubLanguage, Size - 1);
Result := Format('%s-%s', [PrimaryLanguage, SubLanguage]);
Success := True;
end;
end;
if not Success then
raise Exception.Create('Error retrieving locale information');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(GetCurrentInputLanguage);
end;
// Способ четвертый
procedure TForm1.Button2Click(Sender: TObject);
function GetKBLayoutName: string;
begin
SetLength(Result, KL_NAMELENGTH);
GetKeyboardLayoutName(@Result[1]);
SetLength(Result, lstrlen(@Result[1]));
end;
begin
ShowMessage(GetKBLayoutName);
end;
// Способ пятый
procedure TForm1.Button1Click(Sender: TObject);
var
Buffer: PWideChar;
begin
GetMem(Buffer, SizeOf(Char) * KL_NAMELENGTH);
GetKeyboardLayoutName(Buffer);
case ((StrToInt('$' + Buffer)) and $03FF) of
LANG_ENGLISH: Caption := 'Eng';
LANG_RUSSIAN: Caption := 'Rus';
end;
FreeMem(Buffer);
end;
// Способ шестой
procedure TForm1.Button1Click(Sender: TObject);
var
KeyboardLayout: HKL;
begin
//KeyboardLayout := GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow, nil));
KeyboardLayout := GetKeyboardLayout(0);
if KeyboardLayout = 67699721 then
Caption := 'Eng'
else if KeyboardLayout = 68748313 then
Caption := 'Rus';
end;
|