Articles

Use ClipCursor function, which allows you to confine mouse moving in some area.

//Confine mouse
procedure TForm1.Button1Click(Sender: TObject);
var
  Rect: TRect;
begin
  Rect.Left:=Left;
  Rect.Top:= Top;
  Rect.Right:=Left+Width;
  Rect.Bottom:=Top+Height;
  ClipCursor(@Rect);
end;

// Free mouse
procedure TForm1.Button2Click(Sender: TObject);
begin
  ClipCursor(nil);
end;