AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Globaler Maushook in DLL->Callback-Funktion in Programm?
Thema durchsuchen
Ansicht
Themen-Optionen

Globaler Maushook in DLL->Callback-Funktion in Programm?

Ein Thema von Hedge · begonnen am 16. Sep 2008 · letzter Beitrag vom 17. Sep 2008
Antwort Antwort
Hedge

Registriert seit: 30. Jun 2007
278 Beiträge
 
Delphi 2009 Professional
 
#1

Globaler Maushook in DLL->Callback-Funktion in Programm?

  Alt 16. Sep 2008, 22:46
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?
  Mit Zitat antworten Zitat
Benutzerbild von smallsmoker
smallsmoker

Registriert seit: 12. Nov 2007
Ort: Duisburg
283 Beiträge
 
#2

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

  Alt 16. Sep 2008, 22:49
genau bei WH_MOUSE_LL und WH_KEYBOARD_LL musst du nich in einer dll auslagern ...
  Mit Zitat antworten Zitat
Hedge

Registriert seit: 30. Jun 2007
278 Beiträge
 
Delphi 2009 Professional
 
#3

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

  Alt 16. Sep 2008, 23:51
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;
  Mit Zitat antworten Zitat
Benutzerbild von smallsmoker
smallsmoker

Registriert seit: 12. Nov 2007
Ort: Duisburg
283 Beiträge
 
#4

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

  Alt 17. Sep 2008, 01:45
lol PREV_KEY_STATE = PREV_KEY_STATE is doch immer true
  Mit Zitat antworten Zitat
Hedge

Registriert seit: 30. Jun 2007
278 Beiträge
 
Delphi 2009 Professional
 
#5

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

  Alt 17. Sep 2008, 05:20
Voilá:

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

Funktionieren tuts trotzdem nicht.
  Mit Zitat antworten Zitat
Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#6

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

  Alt 17. Sep 2008, 06:18
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
Thomas
  Mit Zitat antworten Zitat
Hedge

Registriert seit: 30. Jun 2007
278 Beiträge
 
Delphi 2009 Professional
 
#7

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

  Alt 17. Sep 2008, 07:39
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 :/
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:47 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz