Search code examples
airprintscreen

Can Adobe AIR Desktop application take full screen snapshots (aka Print Screen button)


I would like to know if its possible to get full screen snapshots from an air application. What i am interested in, is functionality similar to PrintScreen button in windows, which takes snapshots of all screens, including third party application windows, not just window in which air app is running. If its not specific to air, and flash/flex API can provide such functionality, it also would be great. Thanx a lot in advance.


Solution

  • Check out this article as it explains obtaining a screenshot by calling a native process:

    import flash.filesystem.File;
    import flash.events.NativeProcessExitEvent;
    
    var process:NativeProcess;
    
    if(NativeProcess.isSupported) {
    
        var file:File = File.applicationDirectory;
        var args:Vector.<String> = new Vector.<String>();
    
        if (Capabilities.os.toLowerCase().indexOf("win") > -1) {
            file = file.resolvePath("PATH/TO/WINDOWS/printscr");
            //use your prefered screenshot tool here (e.g. https://code.google.com/p/screenshot-cmd/
            //also setup the args as needed
        } else if (Capabilities.os.toLowerCase().indexOf("mac") > -1) {
            file = file.resolvePath("/usr/sbin/screencapture");
            args[0] = "-i";
            args[1] = "screencapture.png";
        }
    
    
    
    
        var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
        nativeProcessStartupInfo.arguments = args;
        nativeProcessStartupInfo.executable = file;
        nativeProcessStartupInfo.workingDirectory = File.desktopDirectory;
    
        process = new NativeProcess();
        process.start(nativeProcessStartupInfo);
        process.addEventListener(NativeProcessExitEvent.EXIT,done);
    
    }else trace("NativeProcess NOT SUPPORTED!");
    
    function done(e:NativeProcessExitEvent):void{
        trace("screenshot comprete");
    }
    

    One important thing to bear in mind is the AIR device profile. If you're initially testing in ADL, be sure to use the extendedDesktop profile, otherwise NativeProcess.isSupported will return false.

    For more details check out the NativeProcess documentation and the Communicating with native processes in AIR developer guide