1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
KeybdHook: HHook;
implementation
{$R *.DFM}
function KeyboardProc(code: Integer; wParam: Word; lParam: LongInt):LResult;Stdcall;
begin
if wParam = VK_RETURN then Form1.Color := clYellow;
Result := 1; // Tester Result := 0;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
KeybdHook := SetWindowsHookEx(WH_KEYBOARD, @KeyboardProc, HInstance, 0);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
UnhookWindowsHookEx(KeybdHook);
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_RETURN then ShowMessage('OnKeyDown');
end;
end. |