procedure TForm1.Timer1Timer(Sender: TObject); var p: TPoint; begin GetCursorPos(p); SetForegroundWindow(WindowFromPoint(p)); end;