Mega Code Archive

 
Categories / Delphi / System
 

Block keyboard and mouse input

// Import BlockInput function form user32.dll: // BlockInput Funktion von user32.dll importieren: function BlockInput(fBlockInput: Boolean): DWORD; stdcall; external 'user32.DLL'; {block input/ blockieren} procedure TForm1.Button1Click(Sender: TObject); begin BlockInput(True); end; {Unblock input / Blockierung aufheben} 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) Bemerkungen: Läuft nur unter Windows 98/2000 und späteren Versionen. Eine Blockierung kann mit CTRL+ALT+DEL aufgehoben werden. Um auch CTRL+ALT+DEL zu verhindern, kann zusätzlich noch SystemParametersInfo(97,Word(True),@OldValue,0); aufgerufen werden und mit SystemParametersInfo(97,Word(False),@OldValue,0); rückgängig gemacht werden. (Var OldValue : Longbool) Um eine Blockierung automatisch nach einer bestimmten Zeit wieder aufzuheben, kann ein Timer eingesetzt werden. } {***********************************************************} {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;