unit Main;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    lKey: TLabel;
    lModifier: TLabel;
    lWindow: TLabel;
    procedure FormCreate(Sender: TObject);
  private
    procedure dwlKeyEvent(Wnd: hwnd; Down,vk,mf: integer) stdcall;
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  wlSetObjKeyCallback(dwlKeyEvent,kDownEvents);
end;

function VkToStr(Window: string; VK, MF: integer): string;
begin
  wlVkToStr(pchar(Window),VK,MF,result);
  if result = '' then
    result := 'None';
end;

procedure TForm1.dwlKeyEvent(Wnd: hwnd; Down, vk, mf: integer);
begin
  lKey.Caption      := VkToStr('',vk,0);
  lModifier.Caption := VkToStr('',0,mf);
  lWindow.Caption   := format('%s (%d)',[GetClassName(Wnd),Wnd]);
end;

end.
