AGB  ·  Datenschutz  ·  Impressum  







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

Tastenabfrage in Hook

Ein Thema von Xerogon · begonnen am 7. Apr 2010 · letzter Beitrag vom 7. Apr 2010
 
Xerogon

Registriert seit: 28. Jan 2010
27 Beiträge
 
#1

Tastenabfrage in Hook

  Alt 7. Apr 2010, 11:03
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:
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 seh mit den Parametern noch nicht ganz durch. was bedeutet lparam und wparam?
Ich denke mal das könnte man eleganter gestalten, nur ich weiß ebend nicht wie
  Mit Zitat antworten Zitat
 


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 21:30 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