Preventing Screenshots (Print Screen) In Full scre

2019-07-31 19:39发布

问题:

I have a need to prevent screenshots made by Print Screen button. And by third party software.

I decided to use fullscreen so they can't use their third party software to make a screenshot.

But I still have no clue how to prevent screenshot.

PS. This app is related to fighting piracy. I don't want my massive ebooks to be shared for free. I thought of videos etc instead but writing is more how I do it.

This way their only method to copy it will be making photos with a HD camera.

Does anyone know if it's possible? I haven't found anything about this.

回答1:

You can not prevent it, but you can try, to a certain extent, overwrite it.
The idea is detect that a print screen was pressed, hide what you want to hide, and invoke another print screen, overwriting the previous one.
This is not robust, and of course has limitations and can be by-passed, but can give you basic control.
This swing basic demonstration was tested on my windows machine:

import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Robot;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; 
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class NoPrintScreen extends JFrame{

    public final String RED_PAGE = "red page";
    public final String WHITE_PAGE = "white page";
    private CardLayout cLayout;
    private JPanel mainPane;
    boolean isRedPaneVisible = false;

    public NoPrintScreen(){

        setTitle("No Print Screen");
        setSize(400,250);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        addKeyListener(new MyKeyListener());
        setFocusable(true);

        mainPane = new JPanel();
        cLayout = new CardLayout();
        mainPane.setLayout(cLayout);

        JPanel whitePane = new JPanel();
        whitePane.setBackground(Color.WHITE);
        whitePane.add(new JLabel("Hit Prtint Screen and check resuts"));

        JPanel redPane = new JPanel();
        redPane.setBackground(Color.RED);
        redPane.add(new JLabel("Print Screen is discouraged"));

        mainPane.add(WHITE_PAGE, whitePane);
        mainPane.add(RED_PAGE, redPane);
        add(mainPane,BorderLayout.CENTER);
        switchPanes();
        setVisible(true);
    }

    void switchPanes() {

        if (isRedPaneVisible) {showRedPane();}
        else { showWhitePane();}
    }

    void showWhitePane() {
        cLayout.show(mainPane, WHITE_PAGE);
        isRedPaneVisible = true;
    }

    void showRedPane() {
        cLayout.show(mainPane, RED_PAGE);
        isRedPaneVisible = false;
    }

    public static void main(String[] args) {
        new NoPrintScreen();
    }

    class MyKeyListener extends KeyAdapter {

        @Override
        public void keyReleased(KeyEvent e) {

            if(KeyEvent.VK_PRINTSCREEN== e.getKeyCode()) {

                switchPanes();

                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {

                        try {

                            final Robot robot = new Robot(); //invoke new print screen
                            robot.keyPress(KeyEvent.VK_PRINTSCREEN);

                        } catch (AWTException  ex) { ex.printStackTrace();  }
                    }
                });

            }
        }
    }
}

The purpose of this quick-code is to demonstrate the idea.



回答2:

Simply answer: you can't.

Creating screen shots is most often a feature of the underlying operating system. A Java application running on top of an OS can't restrict other processes running on that OS. Or restrict features that are provided by that very OS. And even if you could - nothing prevents people from running an OS in a virtual machine, to then screen shot from the host that runs the VM.

Beyond that: creating screen shots is an invaluable feature. You know, maybe somebody wants to create a few screen shots of your application to document its usage for his coworkers. Or somebody wants to have a screen shot here or there to document certain aspects for himself. And now you come along and declare: "sorry, no screen shots at all". That has a certain potential of turning your users away. And there is nothing worse than convincing your users that your product comes with bad user experience.

In that sense, there is no good technical solution to your problem. To the contrary: most likely you will have to spent quite some effort to get anything that is halfway working (and as said: in the VM setup you can do exactly nothing). Instead, I would spend my resources on creating great user experience at reasonable cost. Don't focus your energy on restricting your users.



回答3:

Not in a regular way. You can poll the clipboard and maybe check the list of processes (for a screen grabber application); the latest support for processes is nice. Some exploration needed.