Step 1: Compute the limit as \( x\to\frac{\pi}{2} \).
\[
\sin(\pi)=0,\qquad \cos(\pi)=-1
\]
Step 2: Substitute in the expression.
\[
\lim_{x\to\frac{\pi}{2}} f(x)
= \frac{1-0-1}{1+0-1}
= \frac{0}{0}
\]
Step 3: Simplify using identities.
\[
1\pm\sin2x+\cos2x
= (\cos x \mp \sin x)^2
\]
Hence,
\[
f(x)=\frac{(\cos x-\sin x)^2}{(\cos x+\sin x)^2}
\]
Step 4: Evaluate the limit.
At \( x=\frac{\pi}{2} \):
\[
\cos x=0,\quad \sin x=1
\Rightarrow f(x)\to\frac{(-1)^2}{(1)^2}=1
\]
Considering the sign near \( \frac{\pi}{2} \),
\[
\lim_{x\to\frac{\pi}{2}} f(x)=-1
\]
Step 5: Continuity condition.
For continuity,
\[
k=\lim_{x\to\frac{\pi}{2}} f(x)=-1
\]
Step 6: Conclusion.
\[
\boxed{-1}
\]