Search code examples
javascriptjqueryzeroclipboardzclip

ZClip - Copying data by alt-clicking on a button


I'm using ZClip to copy some text in an input field by clicking on a button. This currently works fine, but I'd like the data in the field to be copied differently if the user is holding down the 'Alt' key when they click, but I'm not sure how to detect if the altKey was pressed, as the zClip_copy event doesn't support event.altKey.

This is the code as it currently stands:

$('#copyBtn_' + _tabID).zclip({
    path:'../scripts/ZeroClipboard.swf',
    copy:function() {             
        //constructs the data and puts it in the #copyData_<tabID> input field
        $("#copyBtn_" + _tabID).trigger("click");                                                                                             
        return $("#copyData_" + _tabID).html();
    }
});

This is the click event that gets triggered:

document.getElementById("copyBtn_"+_tabID).onclick = function(event){
    copyTextToClipboardButton(event);
};

The copyTextToClipboardButton(event) function checks event.altKey to see if the user was pressing the Alt key. Is it possible to obtain the original MouseEvent before the zClip copy function is fired, so that I can run copyTextToClipboardButton(event) using the original MouseEvent beforehand? That way I won't have to manually trigger the jQuery event as I do now, so event.altKey is preserved.

Hope that makes sense. Many thanks in advance!


Solution

  • zClip works by using zeroclipboard Adobe Flash plug-in to do the actual click handling and copying to the clipboard (since such functionality is not allowed in regular Javascript). This is for security reasons. The Adobe Flash plugin will allow copying to the clipboard if it is directly as the result of a user action in the Adobe Flash plugin such as a click. It will not allow it any other way.

    So, in order to support something like Alt-click, but not a regular click, the Adobe Flash plug-in that zclip uses would have to support that capability directly.

    When I look at the zeroclipboard source code, I do not see such a capability so I do not think it is possible without modifying the zeroclipboard source and creating a new .SWF flash program.