Python Forum
How we can prevent screen recording - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How we can prevent screen recording (/thread-37829.html)



How we can prevent screen recording - murad_ali - Jul-27-2022

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.


RE: How we can prevent screen recording - DeaD_EyE - Jul-27-2022

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.


RE: How we can prevent screen recording - murad_ali - Jul-28-2022

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.


RE: How we can prevent screen recording - DeaD_EyE - Jul-29-2022

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()