W tym artykule chciałbym przedstawić a moze bardziej pokazać jak założyć globalnego hooka na klawisze myszy.

A wiec tak:
Zmienne Globalne:

var
  Hook:Integer;
  MessageBuffer:TEventMsg;


Funkcja:
function Play(Code: Integer; wParam, lParam: Longint): Longint; stdcall;
begin
  Case Code of
    HC_ACTION: 
      begin
        MessageBuffer := PEventMsg(lParam)^;
 
        if MessageBuffer.Message = WM_LBUTTONDOWN then
          begin
            Form1.Memo1.Text := Form1.Memo1.Text + '[Left Click]';
            Result := 0;
          end;
 
        if MessageBuffer.message = WM_RBUTTONDOWN then
          begin
            Form1.Memo1.Text := Form1.Memo1.Text + '[Right Click]';
            Result := 0;
          end;
      end;
    else
      begin
       Result := CallNextHookEx(Hook, Code, wParam, lParam);
     end;
  end;
end;


Uzycie:
Hook := SetWindowsHookEx(WH_journalrecord, Play, hInstance, 0);

Kategoria: Delphi » FAQ
4programmers.net