2006. január 21., szombat

Disable Keyboard and Mouse


Problem/Question/Abstract:

How to disable mouse and keyboard for n seconds

Answer:

This Function detect is Function exists in Library (dll)

function FuncAvail(VLibraryname, VFunctionname: string; var VPointer: pointer):
  boolean;
var
  Vlib: tHandle;
begin
  Result := false;
  VPointer := nil;
  if LoadLibrary(PChar(VLibraryname)) = 0 then
    exit;
  VPointer := GetModuleHandle(PChar(VLibraryname));
  if Vlib <> 0 then
  begin
    VPointer := GetProcAddress(Vlib, PChar(VFunctionname));
    if VPointer <> nil then
      Result := true;
  end;
end;

Source code in Button1 on Form1

procedure TForm1.Button1Click(Sender: TObject);
var
  xBlockInput: function(Block: BOOL): BOOL; stdcall;
begin
  if FuncAvail('USER32.DLL', 'BlockInput', @xBlockInput) then
  begin
    xBlockInput(true);
    Sleep(15000); // 15 secounds
    xBlockInput(false);
  end;
end;

Nincsenek megjegyzések:

Megjegyzés küldése