![]() |
Globaler Maushook in DLL->Callback-Funktion in Programm?
Habe jetzt mal so gut wie sämtliche Hook-Tutorials durchgearbeitet und bin zu dem Entschluss gekommen, dass ich WH_MOUSE_LL und WH_KEYBOARD_LL brauche, da JournalHooks an einigen Stellen Probleme machen (Stichwort Parameter).
Damit diese global sind müssen sie in einer DLL eingebunden werden. Mein Problem ist, dass in allen Beschreibungen steht, dass die Callback-Funktion zum jeweiligen Hook in der DLL-Datei stehen muss, jedoch möchte ich lieber mit der Callback-Funktion im Hauptprogramm arbeiten. Wo liegt mein Denkfehler, bzw. wie stelle ich das an? |
Re: Globaler Maushook in DLL->Callback-Funktion in Progra
genau bei WH_MOUSE_LL und WH_KEYBOARD_LL musst du nich in einer dll auslagern ...
|
Re: Globaler Maushook in DLL->Callback-Funktion in Progra
Oh Mann...und ich dachte immer, dass das nur beim Journalhook funktioniert, aber stehe schon wieder vor dem nächsten Problem.
Hier die Hook-Funktion aus Asserbads Tutorial (ein Hook der Typs WH_KEYBOARD_LL wurde gesetzt) :
Delphi-Quellcode:
Wie kriege ich jetzt das 30. Bit des lparam von WM_KEYUP bzw, wie behandle ich WM_KEYUP so dass ich das kann?
function KeyboardHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin //es ist ebenfalls möglich die Bearbeitung an eine Bedingung zu knüpfen //it's possible to call CallNextHookEx conditional only. Result := CallNextHookEx(0, nCode, wParam, lParam); case nCode < 0 of TRUE: exit; //wenn code kleiner 0 wird nix gemacht //if code smaller 0 nothing has to be done FALSE: begin if wparam = WM_KEYUP then beep; end; end; end; Fast das selbe Problem hatte ich schonmal, jedoch habe ich damals einen Journal-Hook benutzt bei dem die Parameter teilweise nicht richtig übergeben werden. Die Lösung sah so aus:
Delphi-Quellcode:
const
PREV_KEY_STATE = 1 shl 30; // $40000000 begin // ... if lparam and PREV_KEY_STATE = PREV_KEY_STATE then Beep; // Ohne Konstante geht es auch so: if Odd(lparam shr 30) then Beep; // .. end; |
Re: Globaler Maushook in DLL->Callback-Funktion in Progra
lol PREV_KEY_STATE = PREV_KEY_STATE is doch immer true
|
Re: Globaler Maushook in DLL->Callback-Funktion in Progra
|
Re: Globaler Maushook in DLL->Callback-Funktion in Progra
Probier's mal so:
Delphi-Quellcode:
if ((lParam shr 30) and 1) = 1 then // Taste erneut gedrückt if ((lParam shr 31) and 1) = 1 then // Taste losgelassen |
Re: Globaler Maushook in DLL->Callback-Funktion in Progra
Zitat:
Grundlegend funktioniert diese Variante. Habe ich lParam getestet den ich in eine KBDLLHOOKSTRUCT gelesen habe. //Key Up if ((lParam.flags shr 7) and 1) = 1 then ShowMessage('Taste wurde losgelassen'); ABER: Die Definition des wParam sieht so aus: Zitat:
Zitat:
Jetzt bräuchte ich das 30. Bit des lParam von WM_KEYDOWN welches der wParam der Callback-Funktion ist. Habe versucht das so hinzukriegen:
Delphi-Quellcode:
Bei der Abfrage If ((wParam^.lparam shr 30) and 1) = 1 then ... gibt es jedes Mal eine Zugriffsverletzung :/
function KeyboardHookProc(nCode: Integer; wParam: PMSG; lParam: PKBDLLHOOKSTRUCT): LRESULT; stdcall;
begin //es ist ebenfalls möglich die Bearbeitung an eine Bedingung zu knüpfen //it's possible to call CallNextHookEx conditional only. Result := CallNextHookEx(0, nCode, cardinal(wParam), Cardinal(lParam)); case nCode < 0 of TRUE: exit; //wenn code kleiner 0 wird nix gemacht //if code smaller 0 nothing has to be done FALSE: begin if ((wParam^.lparam shr 30) and 1) = 1 then ShowMessage('beim ersten Mal tuts noch weh'); end; end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:09 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz