Python Forum

Full Version: How we can prevent screen recording
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
After searching for hours, I have no choice left to ask some python gurus. I want to prevent a user to capture my app window.

I'm currently using tinker. I'm also aware of the C# but I want to do it in python.

I hope there will be SetwindowDisplayAffinity alternative in python. Your reply will be appreciated.

Please note I'm currently new to python.
No matter what you do, you can always record the HDMI signal, and you can get the devices for 4K under 50 €.

I know there is a way to block screen recording in general on Windows. A friend told me this. But he found another way to easily record it.
The reason for making a screen region black in screenshots or video recorder, is that I want to give hard time to non technical people. So, the videos on my app can't be recorded.

And I'm still shocked that we can record HDMI signal even if blocked the screen region?

I know how to make it black in C#, but I want it to do it in python!

As far now I found we use tinker.Frame().winfo_id() to get Window Handle then further we can use ctypes.

And I'm new to python and ctypes looks way much advanced to me.

Can you help me adding flex to that windows handle? Your hints will help me alot.
You can try this, but renaming the name of the application breaks it.

from tkinter import Tk, Label, Button
from tkinter.messagebox import showwarning

# pip install psutil
from psutil import process_iter


def recording_observer(root):
    forbidden = ["obs.exe", "obs64.exe"]
    
    for process in process_iter():
        if process.name() in forbidden:
            root.withdraw()
            showwarning("Recoding", "Recording is not allowed")
            break
    else:
        root.deiconify()

    root.after(1_000, lambda: recording_observer(root))


root = Tk()
Label(root, text="Hello World").pack()
Button(root, text="Close", command=root.destroy).pack()

recording_observer(root)

root.mainloop()