![]() |
Hook funtioniert nicht 'global'
Hallo.
Ich möchte mitbekommen wenn die Strg Taste in irgendeinem Fenster gedrückt wird. Ich habe dazu folgende dll erstellt:
Delphi-Quellcode:
Wenn ich diese im Debugger laufen lasse, sehe ich dass die Ausgabe funktioniert, aber nur wenn das Fenster der Hostanwendung den Fokus hat.
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. Gebe ich einem anderen Fenster den Fokus und drücke Strg dann passiert nichts. Wieso nicht? |
AW: Hook funtioniert nicht 'global'
KeyboardProc:
Zitat:
Zitat:
Delphi-Quellcode:
probiert?
WH_KEYBOARD_LL
|
AW: Hook funtioniert nicht 'global'
Scheint zu funktionieren.
Vielen Dank. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:59 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