Detecting Print Screen in Flash
Listen to this article
:: Talkr
This should be probably the nth time somebody has asked me about this. Thought I will just blog this so someone else who is looking for the same solution would find this useful.
For capturing Print Screen, the traditional Key.addListener(myListener); method wouldn't work and the alternative which I use on my projects is this one and it works:
this.onEnterFrame = function (){
if (Key.isDown(44)) {
trace("Dont try to capture me!");
}
}
Usually this method is used to prevent the user from capturing the screen but definelty this is not a 100% fool prrof method and by the time Flash detects the key press and does something - Windows would have already captured the screen. But yes if you want to warn your user not to take a screen shot you can use this.
If someone out there know of a better solution just post a comment and let the world know of it.




Comments
KP,
Though this code would help you show a fake alert to the user, effectively the printscreen will succeed.
What I would suggest is this:
this.onEnterFrame = function (){
if (Key.isDown(44)) {
trace("Dont try to capture me!");
System.setClipboard("Dont try to capture me!");
}
}
This way, you'll be able to clear the clipboard off the bitmap that was captured, and put up some text of your choice.
Doesn't that solve your problem ?
Posted by: Arul Prasad | February 9, 2006 07:14 AM
Well said Arul ! This is the best solution as far as I know. In my case I wasn't able to use this really because the application was a authoring tool and I have been using System.setClipboard to set some XML string to the clipboard and I didnt want to mess around with the clipboard.
Neverthless, this is the best solution for the screen capture problem.
- kp
Posted by: kp | February 9, 2006 08:44 AM
Hi !
Can't we find a solution without testing onEnterFrame ?
The onKeyDown function wouldn't do the thing ?
Posted by: Quentin | February 9, 2006 10:41 AM
It's too much bother for nothing.
Unless the app you are working on is for an intranet, it's impossible to prevent user from capturing the screen when the RIA is deployed.
http://www.faststone.org/FSCaptureDetail.htm
Posted by: Mike | February 9, 2006 05:34 PM
In the browser, Flash needs focus to detect that the key is down.
Posted by: Robert Penner | February 9, 2006 10:08 PM
Mike: You are true in the sense that there is no 100% fool proof method to prevent someone from capturing the screen but these solutions are just ways to avoid as much as we can. How many people out there would know of the software you mentioned and how many of them would actually take out the time to go and find one just for this purpose.
All said, these solutions are meant only for not-so-technical people - one can even take the SWF from the cache decompile it and simulate the same screen even :)
-kp
Posted by: kp | February 10, 2006 03:03 AM
Robert - You are a perfectly correct that Flash needs to be focused to detect the key. The way we do this is, we have a JavaScript function on the HTML page which can easily detect Print Screen and and take corrective actions and in Flash we have the key detection.
-kp
Posted by: kp | February 10, 2006 03:06 AM
I'd be interested in what JS you're using. But Robert is right, unless Flash is in focus it won't be able to detect the print-screen (and the browser window isn't the only item that can have focus).
If there is a way to detect if Flash has lost focus than you could replace copyrighted material with a "click here to see..." message, bringing back the focus. I've messed around with it for a while however and can't find a solution.
Posted by: Tyler Wright | February 10, 2006 08:10 PM