We need a screenshot of our app for a unit test. CaptureScreen()
and CopyFromScreen()
somehow ignore the app and return pictures of an empty desktop. So we wrote this to fake a PrtScn
keystroke:
public static Bitmap GetAltScreenshot()
{
Clipboard.Clear();
SendKeys.SendWait("{PRTSC}");
while (!Clipboard.ContainsImage())
{
Thread.Sleep(500);
}
return new Bitmap(Clipboard.GetImage());
}
Alt
isn't part of the keystroke, so this should return a bitmap of the entire screen. Yet somehow this snippet returns just the focused window. Which is fine, that solves our problem - but we don't understand how.
Why does this return a shot of just the focused window, instead of the entire monitor?
g.CopyFromScreen
before, as well as every other capture method we could find. They all performed fine on my machine, but gave weird results on other machines within the company. – LathamSendKeys.Flush()
before sending the {PRTSC}, it's kind of a long shot but just to be sure you don't have other messages in the queue it might at least be worth ruling out. – PillorySendKeys.Flush()
has no effect. The code works perfectly with or without it. – Latham