![]() |
Tastenabfrage in Hook
Hallo, ich habe einen kleinen Hook aus einem Tutorial nach gebaut und nun würde ich gerne auch Tasten regaieren.
Also, ich injecte die Hook Dll, drücke eine Taste und anschließend soll ein Meldungsfenster kommen. Das klappt auch schon sehr gut, allerdings denke ich, das der Code viel zu lang ist. Aber genug geredet. Hier der Code
Delphi-Quellcode:
Ich seh mit den Parametern noch nicht ganz durch. was bedeutet lparam und wparam?
library Hook;
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; var HookHandle: Cardinal = 0; WindowHandle: Cardinal = 0; function KeyboardHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; begin Result := CallNextHookEx(HookHandle, nCode, wParam, lParam); case nCode < 0 of TRUE: exit; FALSE: begin if GetAsyncKeyState($41) < 0 then showmessage('A gedrückt'); if GetAsyncKeyState($42) < 0 then showmessage('B gedrückt'); if GetAsyncKeyState($43) < 0 then showmessage('C wurde gedrückt'); if GetAsyncKeyState($44) < 0 then showmessage('D wurde gedrückt'); if GetAsyncKeyState($45) < 0 then showmessage('E wurde gedrückt'); if GetAsyncKeyState($46) < 0 then showmessage('F wurde gedrückt'); if GetAsyncKeyState($47) < 0 then showmessage('G gedrückt'); if GetAsyncKeyState($48) < 0 then showmessage('H gedrückt'); if GetAsyncKeyState($49) < 0 then showmessage('I wurde gedrückt'); if GetAsyncKeyState($4A) < 0 then showmessage('J wurde gedrückt'); if GetAsyncKeyState($4B) < 0 then showmessage('K wurde gedrückt'); if GetAsyncKeyState($4C) < 0 then showmessage('L wurde gedrückt'); if GetAsyncKeyState($4D) < 0 then showmessage('M gedrückt'); if GetAsyncKeyState($4E) < 0 then showmessage('N gedrückt'); if GetAsyncKeyState($4F) < 0 then showmessage('O wurde gedrückt'); if GetAsyncKeyState($50) < 0 then showmessage('P wurde gedrückt'); if GetAsyncKeyState($51) < 0 then showmessage('Q wurde gedrückt'); if GetAsyncKeyState($52) < 0 then showmessage('R wurde gedrückt'); if GetAsyncKeyState($53) < 0 then showmessage('S gedrückt'); if GetAsyncKeyState($54) < 0 then showmessage('T gedrückt'); if GetAsyncKeyState($55) < 0 then showmessage('U wurde gedrückt'); if GetAsyncKeyState($56) < 0 then showmessage('V wurde gedrückt'); if GetAsyncKeyState($57) < 0 then showmessage('W wurde gedrückt'); if GetAsyncKeyState($58) < 0 then showmessage('X wurde gedrückt'); if GetAsyncKeyState($59) < 0 then showmessage('Y wurde gedrückt'); if GetAsyncKeyState($5A) < 0 then showmessage('Z wurde gedrückt'); end; end; end; function InstallHook(Hwnd: Cardinal): Boolean; stdcall; begin Result := False; if HookHandle = 0 then begin 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. Ich denke mal das könnte man eleganter gestalten, nur ich weiß ebend nicht wie |
Re: Tastenabfrage in Hook
Du musst ganz und gar nicht jedes mal abfragen, welche Taste gedrückt wurde. Das gibt die Windows sogar freiwillig.
![]() Das heißt für dich, dass du einfach nur wParam abfragen musst und schon hast du die gedrückte Taste. Bernhard |
Re: Tastenabfrage in Hook
ok, danke.
was sind lparam und wparam eigentlich für Variablentypen? ich seh da nicht durch |
Re: Tastenabfrage in Hook
Zitat:
![]() Die Tastaturüberwachung läßt sich anstatt über eine Hookfunktion - egal, ob von Mikroweich oder selbstprogrammiert - m.E. auch einfacher über ein(en) Hotkey realisieren. |
Re: Tastenabfrage in Hook
Zitat:
![]() Thread #20 |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:51 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 by Thomas Breitkreuz