AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Hook funtioniert nicht 'global'

Ein Thema von Viktorii · begonnen am 24. Jul 2013 · letzter Beitrag vom 25. Jul 2013
Antwort Antwort
Viktorii

Registriert seit: 19. Jul 2007
358 Beiträge
 
#1

Hook funtioniert nicht 'global'

  Alt 24. Jul 2013, 10:36
Hallo.

Ich möchte mitbekommen wenn die Strg Taste in irgendeinem Fenster gedrückt wird. Ich habe dazu folgende dll erstellt:

Delphi-Quellcode:
library CtrlWatch;

uses
  Windows,
  Messages,
  System.SysUtils;

var
  HookHandle: Cardinal = 0;
  WindowHandle: Cardinal = 0;
  WM_HOOK: Cardinal;
  gIsPressed: Boolean = false;

function KeyboardHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
  case nCode < 0 of
    TRUE: exit;
    FALSE:
      begin
        if WParam = VK_CONTROL then
        begin
          if not gIsPressed and (LParam and $80000000 = 0) then
          begin
            gIsPressed := true;
            OutputDebugString('gIsPressed := true');
          end;

          if gIsPressed and (LParam and $80000000 <> 0) then
          begin
            gIsPressed := false;
            OutputDebugString('gIsPressed := false');
          end;
        end;
      end;
  end;

  Result := CallNextHookEx(HookHandle, nCode, wParam, lParam);
end;

function InstallHook(Hwnd: Cardinal): Boolean; stdcall;
begin
  Result := False;
  if HookHandle = 0 then begin
    WM_HOOK := RegisterWindowMessage('WM_HOOK');
    HookHandle := SetWindowsHookEx(WH_KEYBOARD, @KeyboardHookProc, HInstance, 0);
    WindowHandle := Hwnd;
    Result := TRUE;
  end;
end;

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

exports
  InstallHook,
  UninstallHook;
end.
Wenn ich diese im Debugger laufen lasse, sehe ich dass die Ausgabe funktioniert, aber nur wenn das Fenster der Hostanwendung den Fokus hat.

Gebe ich einem anderen Fenster den Fokus und drücke Strg dann passiert nichts.

Wieso nicht?
  Mit Zitat antworten Zitat
Der schöne Günther

Registriert seit: 6. Mär 2013
6.110 Beiträge
 
Delphi 10 Seattle Enterprise
 
#2

AW: Hook funtioniert nicht 'global'

  Alt 24. Jul 2013, 11:45
KeyboardProc:
Zitat:
The system calls this function whenever an application calls the GetMessage or PeekMessage function and there is a keyboard message (WM_KEYUP or WM_KEYDOWN) to be processed.
LowLevelKeyboardProc:
Zitat:
. The system calls this function every time a new keyboard input event is about to be posted into a thread input queue.
Könnte das daran liegen? Mal mit einem WH_KEYBOARD_LL probiert?
  Mit Zitat antworten Zitat
Viktorii

Registriert seit: 19. Jul 2007
358 Beiträge
 
#3

AW: Hook funtioniert nicht 'global'

  Alt 25. Jul 2013, 07:32
Scheint zu funktionieren.

Vielen Dank.
  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 04:39 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