How to block input to the system until released #44

The Windows API BlockInput function prevents all input to the system, making it appear locked up until released. Declare the function as:

function BlockInput(fBlockInput: Boolean): DWORD; stdcall;
  external 'user32.dll';

Usage: Set to True to "lock-up" and False to "unlock" input devices.

The following code locks up input for 2 seconds:

procedure TForm1.Button1Click(Sender: TObject);
begin
  BlockInput(True);
  Label1.Caption := 'Blocked';
  Application.ProcessMessages;
  Sleep(2000);
  BlockInput(False);
  Label1.Caption := 'Unblocked';
end;

Example code added by Peter Johnson

Author: DennisLV
Added: 2007/06/11
Last updated: 2007/06/11