Autor Beitrag
Flips5
Hält's aus hier
Beiträge: 2

Win XP Home SP 1
D6 Pers
BeitragVerfasst: Mo 18.07.05 13:54 
Hallo.

Folgendes:
Ich habe mir mal das Hook Tutorial von Luckie (kein Tutorial, Quelltext) und von Assarbad angeschaut.
Habe mir daraus was zusammen geklebt...

Bin auch fast zufrieden, bis auf das der Hook nur dann aktiv ist, wenn mein Programm den Fokus hat.
Wie kann ich den Hook Systemweit aktivieren?
Hab echt keine Ahnung wie das geht... :gruebel:

Hier Dll Code:

ausblenden volle Höhe Delphi-Quelltext
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:
50:
51:
52:
53:
54:
library TastaturHook;

uses
  Windows,
  Messages;

const
WM_KEYBOARD_HOOK = WM_USER + 52012;
var
HookHandle: Cardinal = 0;
WindowHandle: Cardinal = 0;

function KeyboardHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
  Result := CallNextHookEx(HookHandle, nCode, wParam, lParam);
  case nCode < 0 of
    TRUE:exit;
    FALSE:
      begin
     PostMessage(WindowHandle,WM_KEYBOARD_HOOK,WParam,LParam);
      end;
  end;
end;


function InstallHook(Hwnd: Cardinal): Boolean; stdcall;
var keyhooked: boolean;
begin
  keyhooked := false;
if HookHandle = 0 then
begin
HookHandle := SetWindowsHookEx(WH_KEYBOARD, @KeyboardHookProc, HInstance, 0);;
HookHandle:=1;
end;
  WindowHandle := Hwnd;
  Result := keyhooked;
end;

function UninstallHook: Boolean; stdcall;
var keybh: boolean;
begin
  keybh := UnhookWindowsHookEx(HookHandle);
  HookHandle := 0;
  Result := keybh;
  if Result then WindowHandle := 0;
end;

exports
  InstallHook,
  UninstallHook;

begin

end.

MfG
Flips