Autor Beitrag
Paddymann
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58


Delphi 5 Professional
BeitragVerfasst: So 21.05.06 16:14 
Hi!
Ich versuche gerade einen globalen Keyboard-Hook zu schreiben. Immer wenn eine Taste gedrückt wird soll ein Ton ausgegeben werden. Allerdings kann ich anscheinen nicht die Addresse der Hook Procedure finden und somit den Hook auch nicht installieren. Hier mal der Code:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
//die sehr kurze DLL

function GKeyBoardHook(code: integer; wParam: word; lParam: longword): longword;stdcall;
begin
sysutils.beep;
ShowMessage('beep!');
end;


ausblenden 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:
//das Programm

Form1: TForm1;
  LibHandle: HInst;
  KBHook: HHook;
  HookProc: pointer;  //memory address of hook procedure in windows
...

procedure TForm1.Button1Click(Sender: TObject);    //Button zum installieren der Hooks
begin
//Handle for current Hook
KBHook:=SetWindowsHookEx(WH_KEYBOARD,HookProc,LibHandle,0);
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
//DLL mit Hook Procedure wird geladen
LibHandle := LoadLibrary('GHookDLL.dll');
if LibHandle = 0 then ShowMessage('Konnte DLL nich laden'); //tritt nicht auf
//Handle der Hook Procedure finden
HookProc:=GetProcAddress(LibHandle,'GKeyBoardHook');
if HookProc = nil then ShowMessage('Addresse nicht gefunden');//Fehler tritt auf
end;
//Button zum deinstalieren des HOoks
procedure TForm1.Button2Click(Sender: TObject);
begin
UnhookWindowsHookEx(KBHook);
end;


Es tritt der Fehler Addresse nicht gefunden auf. Was mache ich falsch?

thx und mfg
Patti
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: So 21.05.06 18:26 
hast du in der dll auch stehen:

ausblenden Delphi-Quelltext
1:
2:
  exports
    GKeyBoardHook;


??

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
Paddymann Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58


Delphi 5 Professional
BeitragVerfasst: So 21.05.06 19:11 
Nein hatte ich nicht! :twisted:
Danke jetztz funzt es....
Paddymann Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58


Delphi 5 Professional
BeitragVerfasst: Mo 22.05.06 14:41 
Wie kommt es, dass es immer mehr mals piept und ich 3 Messages bekommen, obwohl ich nur einmal eine Taste gedrückt habe???
Und vor allem wie kann ich das ändern?

thx und mfg
Patti
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Mo 22.05.06 16:41 
Der wParam enthält die Art der Nachricht. z.b. WM_KEYDOWN WK_KEYUP usw. demnach kommt bei einem Druck auf eine Taste mindestens 2 mal der Beep.

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
Paddymann Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58


Delphi 5 Professional
BeitragVerfasst: Mo 22.05.06 16:44 
Und wie kann ich das ändern?
Also das nur z.b. der Keydown gehookt wird?
Paddymann Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58


Delphi 5 Professional
BeitragVerfasst: Di 23.05.06 14:56 
Kann ich da nicht irgendwas mit dem lParam prüfen?
Das ich dann nur tasten hooke die oben sind?
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Di 23.05.06 15:46 
kannd och echt nit so schwierig sein:

ausblenden Delphi-Quelltext
1:
2:
if wParam = WM_KEYDOWN then // oder UP oder sonst was
...

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
Paddymann Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58


Delphi 5 Professional
BeitragVerfasst: Di 23.05.06 16:31 
ja bei mir kennt der WM_Keydown net damit hab ichs schon probiert
welche unit muss ich denn da einbinden??
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Di 23.05.06 16:36 
Du willst hier was mit hooks machen udn hast mal wieder überhaupt keinen Plan von google & Programmieren. Wirds wieder nen Virus mit Keylogger?

Mach ein neues Projekt auf, gib WM_KEYDOWN ein und drück STRG +Klick auf den Text.

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Di 23.05.06 16:36 
Programm erstellen, eine Procedure die auf eine Message reagiert schreiben, um zu testen, ob entsprechende Unit bereits eingebunden ... uses-Klausel ansehen:
ausblenden Quelltext
1:
2:
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

Eine dieser Units. Most likely "Messages" ... ^^

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
Paddymann Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58


Delphi 5 Professional
BeitragVerfasst: Di 23.05.06 21:30 
Mit WM_KEYDOWN funktioniert das nicht. Da wir dgar nichts mehr asugegeben.
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Di 23.05.06 21:37 
Dann funktioniert es bei dir nicht, und du solltest dir mal ein anderes leichteres Projekt suchen.

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit