Thema: Delphi windows keyhooks

Einzelnen Beitrag anzeigen

Benutzerbild von Jan
Jan

Registriert seit: 24. Sep 2002
Ort: Magdeburg
491 Beiträge
 
Delphi 7 Enterprise
 
#1

windows keyhooks

  Alt 11. Mai 2003, 12:29
Hallo DP,
Ich habe ein Programm geschrieben, welches so aussieht:

Delphi-Quellcode:
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, activex, SHDocVw, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    procedure Button1Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  maus:tmouse;
  KBHook: HHook; {this intercepts keyboard input}

function KeyboardHookProc
   (Code: Integer;
   WordParam: Word;
   LongParam: LongInt): LongInt; stdcall;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
setCursorPos(620, 500);
end;

function KeyboardHookProc
   (Code: Integer;
   WordParam: Word;
   LongParam: LongInt) : LongInt;
begin
 case WordParam of
  VK_NUMPAD1   :
   begin
  setCursorPos(600, 390);
  mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
      mouse_event(MOUSEEVENTF_LEFTup, 0, 0, 0, 0);

   end;
   VK_NUMPAD2:
   begin
    setCursorPos(570, 420);
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
        mouse_event(MOUSEEVENTF_LEFTup, 0, 0, 0, 0);
  end;
   VK_NUMPAD3:
   begin
     setCursorPos(570, 470);
     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
         mouse_event(MOUSEEVENTF_LEFTup, 0, 0, 0, 0);

   end;
   VK_NUMPAD4:
   begin
     setCursorPos(600, 510);
     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
         mouse_event(MOUSEEVENTF_LEFTup, 0, 0, 0, 0);

   end;
   VK_NUMPAD5:
   begin
     setCursorPos(630, 540);
     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
         mouse_event(MOUSEEVENTF_LEFTup, 0, 0, 0, 0);

   end;
   VK_NUMPAD6:
   begin
     setCursorPos(680, 540);
     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
         mouse_event(MOUSEEVENTF_LEFTup, 0, 0, 0, 0);

   end;
   VK_NUMPAD7:
   begin
     setCursorPos(720, 510);
     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
         mouse_event(MOUSEEVENTF_LEFTup, 0, 0, 0, 0);

   end;
   VK_NUMPAD8:
   begin
     setCursorPos(750, 470);
     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
         mouse_event(MOUSEEVENTF_LEFTup, 0, 0, 0, 0);

   end;
   VK_NUMPAD9:
      begin
     setCursorPos(750, 430);
     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
         mouse_event(MOUSEEVENTF_LEFTup, 0, 0, 0, 0);

   end;
   VK_NUMPAD0:
   begin
     setCursorPos(730, 380);
     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);

   end;
 end; {case}

Result:=0;
 {To prevent Windows from passing the keystrokes
to the target window, the Result value must
be a nonzero value.}

end;

procedure TForm1.FormActivate(Sender: TObject);
begin
webbrowser1.Navigate('http://www.dummy.de');
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
 UnHookWindowsHookEx(KBHook);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 {Set the keyboard hook so we
can intercept keyboard input}

 KBHook:=SetWindowsHookEx(WH_KEYBOARD,
           {callback —>}  @KeyboardHookProc,
                          HInstance,
                          GetCurrentThreadId());

end;
end.
Das klappt auch schön, ausser einem Makel: es wird immer Doppelgeklickt. Wie kann ich das abstellen?
Gruß
Jan
Jan
Wenn die Sonne der Kultur tief steht, werfen auch kleine Gestalten lange Schatten.
  Mit Zitat antworten Zitat