Mega Code Archive

 
Categories / Delphi / Hardware
 

How to block keyboard and mouse input

Title: How to block keyboard and mouse input // Import BlockInput function form user32.dll: function BlockInput(fBlockInput: Boolean): DWORD; stdcall; external 'user32.DLL'; {block input} procedure TForm1.Button1Click(Sender: TObject); begin BlockInput(True); end; {Unblock input } procedure TForm1.Button2Click(Sender: TObject); begin BlockInput(False); end; { Notes: Requires Windows 98/2000 or later. You can unblock input by pressing CTRL+ALT+DEL If you don't want the user to unblock by pressing CTRL+ALT+DEL, additionally write: SystemParametersInfo(97,Word(True),@OldValue,0); and to undo it: SystemParametersInfo(97,Word(False),@OldValue,0); (Var OldValue : Longbool) If you want to unblock your input after pressing button1 the simple way to do it is use timer (just set it for few sec and tell it to unblock input after counting down) } {***********************************************************} {Function from Babak Sateli babak_sateli@yahoo.com www.cdcenterco.com} function FunctionDetect(LibName, FuncName: string; var LibPointer: Pointer): Boolean; var LibHandle: THandle; begin Result := False; LibPointer := nil; if LoadLibrary(PChar(LibName)) = 0 then Exit; LibHandle := GetModuleHandle(PChar(LibName)); if LibHandle 0 then begin LibPointer := GetProcAddress(LibHandle, PChar(FuncName)); if LibPointer nil then Result := True; end; end; // On Button Click Even procedure TForm1.Button1Click(Sender: TObject); var xBlockInput: function (Block: BOOL): BOOL; stdcall; begin if FunctionDetect('USER32.DLL', 'BlockInput', @xBlockInput) then begin xBlockInput(True); // Disable Keyboard & mouse Sleep(10000); // Wait for 10 Seconds xBlockInput(False); // Enable Keyboard & mouse end; end;