0
votes

The beautiful thing about creating desktop apps in Adobe AIR is that I can still use my web development skills to do so.

For some reason, I am running into a slight issue with detecting what's in the clipboard, and displaying it in my App.

Here's my code:

<body>
<div id="infoDiv"></div>

<script>
function everysecond() {
    setInterval("checkClipBoard()",1000);       
}   


function checkClipBoard(){

    if(air.Clipboard.generalClipboard.hasFormat("text/plain")){ 
        var text = air.Clipboard.generalClipboard.getData("text/plain"); 
    }else{
        var text = "nothing in clipboard"; 
    }

    $("#infoDiv").html(text);

}

everysecond();
</script>
</body>

Whether my app is in Focus or not, it doesn't seem to detect anything I Copy to the clipboard (Ctrl + C)

Anyone see my issue?

2
Don't pass a string to setTimeoutSLaks

2 Answers

0
votes

Clipboard polling is a terrible hack. You will be conflicting with other apps that are (legitimately) opening the clipboard. So while your app runs, you'll be causing failures (and possibly crashes) in other apps where the user is trying to copy/paste data. Have you ever seen "cannot open clipboard" errors? It's things like this that cause them. I don't know what capabilities are available to you in Air, but if there isn't a clipboard notification feature (WM_DrawClipboard messages, for example), then you should probably re-think the need for what you're trying to do here.

This says it best:

“Programs should not transfer data into our out of the clipboard without an explicit instruction from the user.” — Charles Petzold, Programming Windows 3.1, Microsoft Press, 1992

0
votes

From the docs:

Only code running in the application sandbox can access the system clipboard 
directly. In non-application HTML content, you can only access the clipboard 
through the clipboardData property of an event object dispatched by one of 
the HTML copy or paste events.

If your HTML content is outside the application sandbox this might be the problem.