How do I prevent taking screenshots of my application?

Hi,
How do I prevent taking screenshots of my application’s main window?
I tested the undocumented API first: Declare Function CGSSetWindowCaptureExcludeShape Lib “ApplicationServices” (cid As UInt32, wid As UInt32, region As Ptr) As Integer, used by KeepassXC app, but it seems to no longer work…
then function “NSWindowSharingNone” of sharingType property on NSWindow with this code. It compiles but does not seem to prevent capture… If you have any information to move forward, I am interested…

Sub DisableWindowCapture()
  #If TargetMacOS Then
    // Déclaration pour obtenir l'instance NSApplication
    Declare Function NSClassFromString Lib "Cocoa" (aClassName As CFStringRef) As Ptr
    Declare Function sharedApplication Lib "Cocoa" Selector "sharedApplication" (NSApp As Ptr) As Ptr
    Declare Function mainWindow Lib "Cocoa" Selector "mainWindow" (NSApp As Ptr) As Ptr
    Declare Sub setSharingType Lib "Cocoa" Selector "setSharingType:" (NSWindow As Ptr, sharingType As Integer)
    
    Const NSWindowSharingNone = 0
    
    // Obtenir l'instance partagée de l'application
    Dim appClass As Ptr = NSClassFromString("NSApplication")
    Dim sharedApp As Ptr = sharedApplication(appClass)
    
    // Obtenir la fenêtre principale
    Dim mainWnd As Ptr = mainWindow(sharedApp)
    
    // Définir le SharingType de la fenêtre principale sur None
    setSharingType(mainWnd, NSWindowSharingNone)
    
  #EndIf
End Sub
Sub Opening()
  DisableWindowCapture()
  System.DebugLog("La capture d'écran de cette fenêtre est désactivée.")
End Sub

Thanks
Dan

In my opinion, do not waste your time trying.
No matter what you do, phones with cameras exist.

7 Likes

for DRM protected media it works, you will see only black content,
so i guess it is a flag which can be set possibly in the window api.

https://learn.microsoft.com

dans ta fenetre tu places un evenement sur keyDown ou keyUp qui va detecter le raccourcis clavier
Sur un mac : commande + maj + 4 et certains autres
Sur un PC: sais pas car je n’ai jamais acheté de PC de ma vie