Title: restrict the mouse movement to form
Question: Using the Windows API function ClipCursor, it is possible to restrict the movement of the mouse to a specific rectangular region on the screen.
Answer:
{
Using the Windows API function ClipCursor, it is possible to restrict the movement of the mouse to a specific rectangular region on the screen:
}
//restrict the mouse mouvement to form and release
//this restriction after a click on the form
procedure TForm1.FormCreate(Sender: TObject);
var r : TRect;
begin
//it would be good idea to move the
//mouse inside the form before restriction
r := BoundsRect;
ClipCursor(@R);
end;
procedure TForm1.FormClick(Sender: TObject);
begin
//always be sure to release the cursor
ClipCursor(nil);
end;