Autor Beitrag
Tana´Ri
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 230



BeitragVerfasst: Di 24.06.03 15:22 
Hi tino,

wirklich tolles tutorial ! :shock:

ich hab irgendwie ein prob, der keyboardhook sollte doch global sein, funktioniert bei mir aber nur wenn des Form den Focus hat, hab mich eigentlich eng an deine vorlage gehalten um mal die funktionalität zu testen.
Dann hätte ich noch ne andere frage, ich würde gerne eine offene install prozedur für meine dll schreiben, sodas ich ihr per referenz die entsprechende hookproc (die natürlich dann individuell ausserhalb geschrieben wird) zuweise, ist dieser hook dann immer noch global wirksam ? oder muss ich etwa immer meine dll erweitern.


hier is der 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:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
library My_Hook;


uses
  Windows,
  Messages;

{$R *.res}


Const WM_HOOKMESSAGEID = WM_USER + 5000;


Type  THookProc = function (nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;


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_HOOKMESSAGEID,Integer(wParam),Integer(LPARAM));
         end;
 end;
end;

// -------------------------------------------------------------------------- //

function InstallKeyboardHook(Hwnd: Cardinal): Boolean; stdcall;
 begin
  Result := False;
  if HookHandle = 0 then
   begin //Erstmal Hook installieren //First install the hook
    HookHandle := SetWindowsHookEx(WH_KEYBOARD, @KeyboardHookProc, HInstance, 0); //Uebergebenes Fensterhandle sichern //Save the given window handle
    WindowHandle := Hwnd;
    Result := TRUE;
  end;
end;

// -------------------------------------------------------------------------- //

function InstallHook( IDHook : integer; HookProc : THookProc ): Cardinal; stdcall;
 begin
  Result := 0;
  if (HookHandle = 0)AND(@HookProc<>NILthen
   begin
    HookHandle := SetWindowsHookEx(IDHook, @HookProc, HInstance, 0);
    Result := HookHandle;
  end;
end;

// -------------------------------------------------------------------------- //

function UninstallHook: Boolean; stdcall;
 begin
  Result := UnhookWindowsHookEx(HookHandle);
  HookHandle := 0;
end;

// -------------------------------------------------------------------------- //

exports
 InstallKeyboardHook,
 InstallHook,
 UninstallHook;

// -------------------------------------------------------------------------- //

begin

end.// ------------------------------------------------------------------ FIN //


Moderiert von user profile iconTino: Topic getrennt; Link eingefügt; Code- durch Delphi-Tags ersetzt.

_________________
mfg
Tana´Ri
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Di 24.06.03 15:29 
Tana´Ri hat folgendes geschrieben:
Hi tino,

wirklich tolles [url=www.delphi-forum.de/...t=101]tutorial[/url]

Das Tutorial ist nicht von mir sondern von Assabad. Ich hab es hier nur veröffentlicht.

Gruß
Tino
Gast
Gast
Erhaltene Danke: 1



BeitragVerfasst: Di 24.06.03 18:07 
IMHO ist dies eine ältere Version. Ich bin gerade dabei die letzte Version zu überarbeiten. Wahrscheinlich ist sie morgen fertig. Wenn du also noch warten kannst ...