How to Capture Full Game Window Even When Obscured by Other Windows By using OBS API?

dhoizxc

New Member
Hi everyone,

I'm working on a project where I need to capture the content of a game window, even when the window is partially or fully covered by other applications (like floating toolbars, overlays, or other always-on-top windows).

OBS seems to be able to do this with its "Game Capture" mode, which successfully captures the rendered frames even when the game window is behind other windows. I’m trying to understand:

- How does OBS achieve this under the hood?
- Is it using something like a DirectX or OpenGL hook?
- Can similar functionality be achieved programmatically (e.g. via C++, C#, or Python)?
- Is there any way to replicate this using the Windows.Graphics.Capture API or other modern Windows tools?

I’m currently experimenting with Python, but I’m open to switching to another language if needed.

Thanks in advance!
 

koala

Active Member
As far as I know, the game capture source works by injecting code into the destination process (into the game), then hook some Windows DirectX/Vulcan/OpenGL calls. Injecting is required, because some functionality for grabbing image data most efficiently can only be executed by the owning process (the game) and not by an external app (OBS).

In its original form, this injection was quite intrusive, it patches code in the running game to establish the hook, because corresponding API calls don't natively support being hooked. I don't know if this patching is still being done, but injecting in general is still the case - it's graphics-hook32.dll and graphics-hool64.dll that's being injected.

The modern Windows API supports high level capturing app windows as you found out, but it's probably not as resource conserving as the game capture method. And OBS tries to be really invisible if it comes to resource utilization.

If you don't care that much for performance, you can very easily just get the window handle of the window you want to capture and use some Windows GDI calls to grab image data from it. No injecting required, just the window handle. This is the "BitBlt" capture method you see in the Window capture source properties. This is the oldest method and works even with scripting languages like Autohotkey, where it is mostly being used for game bots - no OBS API or library required. Just a bunch of Win32 GDI DLL calls: GetDC/CreateCompatibleDC/CreateDIBSection/SelectObject/BitBlt. I guess any AI chat interface like ChatGPT and Copilot is able to provide you with working example code for any programming language that support calling DLLs or have corresponding wrapper modules.
 

dhoizxc

New Member
Thanks for your reply! I have little skills in C++ and win api. But I found a Python solution just now, it perfectly solve my problem: supporting screenshot the entire game window although it is obstructed by other applications.
 

upgradeQ

Member
Python solution looks quite interesting - thanks for the post!

1) There is no docs or specification regarding how OBS implements this. I guess you can read the source code.
2) Yes, signed and whitelisted hooks are used for different APIs.
3) C++ sure, C# maybe, but pure Python internal DirectX capture or hooking is very difficult, almost impossible.
4) It seems you've found a library, but there are other approaches as well; see

In modern games, I don't think BitBlt will ever work because of TPM anti-cheats, DRMs. All you get from it is a black screen or an error.
Additionally, it is impossible to capture minimized windows.
If you move from Python to a compiled language without GC, your real-time graphics stuff will run faster and your program will be easier to distribute.
 
Top