Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Globaler Maushook in DLL->Callback-Funktion in Programm? (https://www.delphipraxis.net/120801-globaler-maushook-dll-callback-funktion-programm.html)

Hedge 16. Sep 2008 22:46


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?

smallsmoker 16. Sep 2008 22:49

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 ...

Hedge 16. Sep 2008 23:51

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:
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;
Wie kriege ich jetzt das 30. Bit des lparam von WM_KEYUP bzw, wie behandle ich WM_KEYUP so dass ich das kann?

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;

smallsmoker 17. Sep 2008 01:45

Re: Globaler Maushook in DLL->Callback-Funktion in Progra
 
lol PREV_KEY_STATE = PREV_KEY_STATE is doch immer true

Hedge 17. Sep 2008 05:20

Re: Globaler Maushook in DLL->Callback-Funktion in Progra
 
Voilá:

http://www.delphipraxis.net/internal...keydown+lparam

Funktionieren tuts trotzdem nicht.

toms 17. Sep 2008 06:18

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

Hedge 17. Sep 2008 07:39

Re: Globaler Maushook in DLL->Callback-Funktion in Progra
 
Zitat:

Zitat von toms
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


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:

wParam
[in] Specifies the identifier of the keyboard message. This parameter can be one of the following messages: WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP.
und die von WM_KEYDOWN so:

Zitat:

WM_KEYDOWN
WPARAM wParam
LPARAM lParam;

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:
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;
Bei der Abfrage If ((wParam^.lparam shr 30) and 1) = 1 then ... gibt es jedes Mal eine Zugriffsverletzung :/


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