Thema: Delphi Tastatursperre mit Hook

Einzelnen Beitrag anzeigen

Wotan89

Registriert seit: 20. Nov 2007
77 Beiträge
 
Delphi 2005 Personal
 
#1

Tastatursperre mit Hook

  Alt 30. Nov 2007, 14:05
Ich hab schon wieder ein Problem, wo ich einfach nicht weiter weiß: Ich wollte ein Programm für eine Tastensperre schreiben, welche mit der Taste + an und ausgeht. (Sozusagen eine kleine Kindersicherung). Dies wollte ich über Hooks regeln.
hier ist meine DLL für den Tastaturhook:
Delphi-Quellcode:
library Project2;

uses
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;


var
hook:cardinal; switch:boolean; //{switch ist meine Variable, welche regeln soll, ob bei + die Tastensperre an oder ausgeht}
 {$R *.res}
function show(ncode,wparam,lparam:integer):lresult; stdcall;
var help:integer; f : file of cardinal;
begin
help:=Callnexthookex(hook, ncode, wparam, lparam);
if wparam=107 then switch:=not switch;
if not switch then result:=help;
end;

function hookinstall:boolean; stdcall;
var f:file of cardinal;
begin
result:=false;
hook:=0;
switch:=true;
hook:=setwindowshookex(WH_Keyboard,@show,HInstance, 0);
if hook <> 0 then
result:=true;
end;

function hookuninstall:boolean;stdcall;
begin
result:=false;
unhookwindowshookex(hook);
result:=true;
end;

exports
show,
hookinstall,
hookuninstall;
begin
end.
Und hier meine exe:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
    dll1:thandle;
implementation
                                                      
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var install:function:boolean; stdcall;
begin
dll1:=loadlibrary('project2.dll');
install:=getprocaddress(dll1,'hookinstall');
install;
end;

procedure TForm1.Button2Click(Sender: TObject);
var uninstall:function:boolean; stdcall;
begin
uninstall:=getprocaddress(dll1,'hookuninstall');
uninstall;
end;

end.
Ich hoffe ihr könnt mir helfen und vllt. ein paar Verbesserungsvorschläge anbringen
  Mit Zitat antworten Zitat