본문 바로가기

카테고리 없음

[윈도우즈 API] 지원하는 키보드 입력 언어 구하고 변경하기

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    procedure FormCreate(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure GetKLList(List: TStrings);
var
  AList : array [0..9] of Hkl;
  AklName: array [0..2] of Char;
  i: Longint;
begin
  List.Clear;
  for i := 0 to GetKeyboardLayoutList(SizeOf(AList), AList)-1 do
    begin
      GetLocaleInfo(LoWord(AList[i]),
                    LOCALE_SABBREVLANGNAME,
                    AklName,
                    SizeOf(AklName));
      List.AddObject(AklName, Pointer(AList[i]));
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  GetKLList(ListBox1.Items);
  ListBox1.ItemIndex := 0;
end;

procedure TForm1.ListBox1Click(Sender: TObject);
begin
  with Sender as TListBox do
  begin
    ActivateKeyboardLayout(Hkl(Items.Objects[ItemIndex]), 0);
    ShowMessage('키보드 레이아웃이 '+Items.Strings[ItemIndex]+'로 변경되었습니다');
  end;  
end;

end.