View Full Version : Copy and Paste in Input Text problems
shawn_t
07-31-2007, 02:39 AM
I have written a Flash Projector in C++ using an ActiveX control. The problem I am currently encountering is when trying to use CTRL+C and CTRL+V to copy and paste text within an input text box. When running from within the Flash Player it seems to work, but it doesn't work from my C++ projector. I added the following Key listener to try to figure out what is going on:
keyObj = {};
keyObj.onKeyDown = function()
{
if (Key.isDown(Key.CONTROL) and Key.isDown(67))
{
if (Selection.getFocus() != null)
{
logger.info("Copy: ");
logger.info(eval(copy));
}
}
else if (Key.isDown(Key.CONTROL) and Key.isDown(86))
{
logger.info("Paste");
if (Selection.getFocus() != null)
{
logger.info("Paste: ");
logger.info(eval(copy));
}
}
}
Key.addListener(keyObj);
and the multi-key combinations don't get triggered in the Flash Player. It seems like the Flash Player is filtering out the CTRL combination keystrokes or something?!? In my C++ projector, Key.isDown(Key.CONTROL) and Key.isDown(67) gets properly evaluated, but the selection is replaced with a bottom-left corner when pressing CTRL+C and a T-intersection down when pressing CTRL+V.
Anybody encountered this?
cmbarsotti
08-03-2007, 03:52 PM
I have.
I'm not as smart as you, I'm using mProjector and they have comments about this on their site (http://www.screentime.com/faqs/mProjector/technote247.html. They say to do what you did, which I did, and it doesn't work for me.
I can copy the text from a Flash input box and paste it into Notepad or an email, but pasting it into another (Flash) input box I get a square.
shawn_t
08-09-2007, 10:37 PM
I figured out that for some CTRL combinations windows actually generates multiple messages. For example, CTRL+C will generate:
WM_KEYDOWN: VK_CONTROL
WM_KEYDOWN: 0x43 (ASCII for 'C')
WM_CHAR: VK_CANCEL (0x03)
I believe the problem is that flash is received the VK_CANCEL and trying to draw ASCII character 0x03 which ends up replacing the selection with a garbage character.
I have modified my projector to filter out the sending of non-drawable WM_CHAR messages and this seems to avoid the garbage characters in flash. I will now try to implement the suggested code to see if I can get the copy and paste to actually work!
shawn_t
08-10-2007, 01:13 AM
I implemented the cut, copy and paste code and it now works properly. Here is the current code I'm using to handle CUT, COPY and PASTE:
var mSelectText:String = new String();
var keyObj:Object = new Object();
keyObj.onKeyDown = function()
{
if (Selection.getFocus() != null)
{
var selectTextArea;
var keyCode:Number = Key.getCode();
if (Key.isDown(Key.CONTROL))
{
if (keyCode == 99 || keyCode == 67) // C or c
{
selectTextArea = eval(Selection.getFocus());
if (selectTextArea.getBeginIndex() >= 0)
{
mSelectText = selectTextArea.text;
mSelectText = mSelectText.substring(Selection.getBeginIndex(), Selection.getEndIndex());
}
}
if (keyCode == 88 || keyCode == 120) // X or x
{
selectTextArea = eval(Selection.getFocus());
if (selectTextArea.getBeginIndex() >= 0)
{
mSelectText = selectTextArea.text;
mSelectText = mSelectText.substring(Selection.getBeginIndex(), Selection.getEndIndex());
selectTextArea.text = selectTextArea.text.substring(0, Selection.getBeginIndex()) +
selectTextArea.text.substring(Selection.getEndInde x());
Selection.setSelection(Selection.getBeginIndex(), Selection.getBeginIndex());
}
}
if (keyCode == 118 || keyCode == 86) // V or v
{
if (mSelectText.length > 0)
{
selectTextArea = eval(Selection.getFocus());
selectTextArea.text = selectTextArea.text.substring(0, Selection.getBeginIndex()) +
mSelectText + selectTextArea.text.substring(Selection.getEndInde x());
Selection.setSelection(Selection.getEndIndex(), Selection.getEndIndex());
}
}
}
}
}
Key.addListener(keyObj);
northcode
08-29-2007, 05:31 AM
Or you could have added code to pre-translate accelerator messages to your window's message loop in your C++ project. That would translate the raw keystroked into the correct windows messages before they get to the Flash player and would have required no code changes in your FLA. That's pretty much how I do it in SWF Studio ;)
shawn_t
12-02-2007, 03:32 AM
Can you provide a code snippet or some pseudocode for what you mean?
northcode
12-02-2007, 07:27 PM
Check out the documentation for TranslateAccelerator
http://msdn2.microsoft.com/en-us/library/ms646373.aspx
mish123
06-19-2008, 02:52 PM
Usually the C++ container for activex objects such as Flash (see http://www.codeproject.com/KB/COM/flashcontrol.aspx) implements IOleInPlaceFrame. The contained Flash object calls IOleInPlaceFrame::SetActiveObject to set the IOleInPlaceActiveObject, use this object to call IOleInPlaceActiveObject::TranslateAccelerator in your application to let Flash handle the key combination, you should call it in your message loop code such as:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
replacing TranslateAccelerator with IOleInPlaceActiveObject::TranslateAccelerator.
Good luck.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.