I would like some assistance on how to either disable or lock keyboard input to prevent the user from interrupting a critical task. Any ideas, hints or code examples will be highly appreciated.
Hi. If you mean a key interruption for the form you're working in, then you could set KeyPreview to True and ignore all keypresses for as long as your proces is running.
You could also run your proces from within a thread, which you can set to HighPriority.
Note that you're in a multitasking environment, and your user should be able to switch between different processes. Probably the best option is to run a separate thread.
hth, pritaeas
: I would like some assistance on how to either disable or lock : keyboard input to prevent the user from interrupting a critical task. : Any ideas, hints or code examples will be highly appreciated.
[b][red]This message was edited by mohfa at 2004-5-7 0:11:50[/red][/b][hr] : Hi. If you mean a key interruption for the form you're working in, then you could set KeyPreview to True and ignore all keypresses for as long as your proces is running. : : You could also run your proces from within a thread, which you can set to HighPriority. : : Note that you're in a multitasking environment, and your user should be able to switch between different processes. Probably the best option is to run a separate thread. : : hth, pritaeas : : : I would like some assistance on how to either disable or lock : : keyboard input to prevent the user from interrupting a critical task. : : Any ideas, hints or code examples will be highly appreciated. : : ** OK my friend use this unit and ( good luck )**
// 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 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 Event
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;
Comments
You could also run your proces from within a thread, which you can set to HighPriority.
Note that you're in a multitasking environment, and your user should be able to switch between different processes. Probably the best option is to run a separate thread.
hth, pritaeas
: I would like some assistance on how to either disable or lock
: keyboard input to prevent the user from interrupting a critical task.
: Any ideas, hints or code examples will be highly appreciated.
: Hi. If you mean a key interruption for the form you're working in, then you could set KeyPreview to True and ignore all keypresses for as long as your proces is running.
:
: You could also run your proces from within a thread, which you can set to HighPriority.
:
: Note that you're in a multitasking environment, and your user should be able to switch between different processes. Probably the best option is to run a separate thread.
:
: hth, pritaeas
:
: : I would like some assistance on how to either disable or lock
: : keyboard input to prevent the user from interrupting a critical task.
: : Any ideas, hints or code examples will be highly appreciated.
:
: ** OK my friend use this unit and ( good luck )**
// 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)
}
{***********************************************************}
// form function
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 Event
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;