python-mss: Fullscreen doesn't capture as expected with fullscreen game
Hi,
I was under the impression that this package should be able to make game screenshot. I did the following :
import time
#launch script then alt+tab to game
n_seconds = 5
for x in range(n_seconds):
print "taking screenshot in {}".format(n_seconds-x)
time.sleep(1)
from mss.windows import MSS as mss
sct = mss()
filename = sct.shot(output='test.png')
However all I’m getting is this :
https://www.dropbox.com/s/yy5qnltobdp02v6/test.png?dl=0
Is this what is expected? Thanks.
About this issue
- Original URL
- State: open
- Created 7 years ago
- Comments: 15 (8 by maintainers)
Turns out that it was a problem with Pynput keyboard listener, i used a shortcut to take the screenshot, it needed elevated privileges to work with games (Why?). All good, friend, sorry 😉
I’d guess this is because “Fullscreen” in games (versus “Borderless Window” or the like) uses “Exclusive Mode”/“Active Rendering” wherein the application itself works directly with the GPU to write to the screen, as opposed to to working with the window manager.
It’s not impossible to take screenshots per se, but you won’t be able to do so through the window manager APIs. In the case of video games (or anything using DirectX in exclusive mode) it’s usually done through DLL injection to hook into DirectX drawcalls.
(A cursory examination of
windows.pyappears to indicate as well that only capturing of the first screen is supported as well, owing to the hardcoded argument toctypes.windll.user32.GetWindowDC.)