Board index » delphi » Disable mouse, while not disabling keyboard?

Disable mouse, while not disabling keyboard?

How can I disable the mouse for a while?

I found the following:

--------------------------
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;

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 for 10 Secounds
  xBlockInput (False); // Enable  Keyboard & mouse
 end;
end;
-------------------------

Unfortunately, I cannot use this, because it also disables the keyboard.
What I am making is a demo mode for a program I am writing.
It all looks very nice; you can see the mouse moving on it's own, opening
windows, pressing buttons etc.
But, if the user tries, he can move the mouse on certain moments, thus
disrupting the process.
I want to make this impossible.

The demo mode is a continuous process ( a loop), which can be interrupted by
pressing Esc.
That is why I still need an enabled keyboard, while the mouse is temporarily
out of control of the user.

Is it possible?

Niko

 

Re:Disable mouse, while not disabling keyboard?


You could write a global mousehook to filter mouse messages.
The following example contains an example of a global keyboard hook:
http://delphifaq.com/fq/q2108.shtml

Quote
"Niko" <n...@n.net> wrote in message news:9r96ka$3ht$1@reader06.wxs.nl...
> How can I disable the mouse for a while?

> I found the following:

> --------------------------
> 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;

> 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 for 10 Secounds
>   xBlockInput (False); // Enable  Keyboard & mouse
>  end;
> end;
> -------------------------

> Unfortunately, I cannot use this, because it also disables the keyboard.
> What I am making is a demo mode for a program I am writing.
> It all looks very nice; you can see the mouse moving on it's own, opening
> windows, pressing buttons etc.
> But, if the user tries, he can move the mouse on certain moments, thus
> disrupting the process.
> I want to make this impossible.

> The demo mode is a continuous process ( a loop), which can be interrupted
by
> pressing Esc.
> That is why I still need an enabled keyboard, while the mouse is
temporarily
> out of control of the user.

> Is it possible?

> Niko

Other Threads