views:

240

answers:

2

I know that you can use the context menu using a right-mouse-click in a control to choose to cut, copy, paste, etc. I've also noticed that you can use the windows keyboard shortcuts CTRL-C for Copy and CTRL-V for Paste.

Windows supports native CTRL-Insert (for copy) and SHIFT-Insert (for paste).

However, within Flex, it seems these do not appear to work. Has anyone been able to either allow these keyboard events? Any solutions are appreciated.

+1  A: 

Note: The operating system and the web browser will process keyboard events before Adobe Flash Player or AIR. For example, in Microsoft Internet Explorer, pressing Ctrl+W closes the browser window before any contained SWF file dispatches a keyboard event.

You can just do something similar to this

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
 layout="absolute" creationComplete="init()">

 <mx:Script>

 <![CDATA[

    private function init():void{

     this.addEventListener(MouseEvent.CLICK, clickHandler);

     this.addEventListener(KeyboardEvent.KEY_DOWN,keyPressed);

    }

    private function clickHandler(event:MouseEvent):void {

      stage.focus = this;

    }

    private function keyPressed(evt:KeyboardEvent):void{

       if(evt.ctrlKey && evt.keyCode == 65)

             trace("CTRL A is pressed");

       if(evt.ctrlKey && evt.keyCode == 66)

             trace("CTRL B is pressed");

   }

 ]]>

 </mx:Script>

</mx:Application>

Then To write to the operating system clipboard:

import flash.desktop.ClipboardFormats;

 var copy:String = "A string to copy to the system clipboard.";
 Clipboard.generalClipboard.clear();
 Clipboard.generalClipboard.setData(ClipboardFormats.TEXT_FORMAT, copy);

To read from the operating system clipboard:

import flash.desktop.ClipboardFormats;

 var pasteData:String  = Clipboard.generalClipboard.getData(ClipboardFormats.TEXT_FORMAT) as String;
Todd Moses
I am using Flex Builder 3 and dont see where I can import flash.desktop. I've only found the following, but it only lets you paste to the windows clipboard. I actually haven't tested it, but I'm still trying to find a way to paste into a TextInput. I already wrote the KeyboardEvent code to grab the Shift-Insert event. I just don't know how to gain access to the system clipboard. Maybe I'm missing flash.desktop.* somehow.import flash.system.System;System.setClipboard(string);
bugsmash
It is in AIR Only.http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/desktop/Clipboard.html
Todd Moses
+1  A: 

Clipboard class is available starting from Flash Player 10.

JabbyPanda