- Home /
Copy/Paste Key Combos in Webplayer
I'm implementing copy and paste functionality in our app. I found a thread that addresses getting info from the system clipboard and tested it out; it appears to work fine:
http://forum.unity3d.com/threads/24101-Copy-TextField-or-TextArea-text-to-Clipboard
Now I'm working on recognizing when the user has pressed a copy/paste key combo (like Control-V). In the standalone application, Input.GetKey* works just fine. I can check if the user is holding down the control/command key and presses C or V, and act accordingly.
However, in the webplayer and editor, this is not the case. It looks like the surrounding application (editor or browser) is catching the copy/paste key combinations and isn't passing them on to Unity. I can see control presses, I can see V presses, but I get no notification when the user presses control-V.
I've seen some discussion in other threads (like this one: http://answers.unity3d.com/questions/49285/how-can-i-get-a-combination-of-keys-pressed.html ), and have some things to try, but I'm hopeful that someone else has already figured this out and can save me the pain.
So, the question: is there any way to determine if the user has pressed control-v in the webplayer? If not, is there any way to get notice from the browser when the user copies or pastes?
Update: submitted bug 542262 to Unity concerning this a while back. They have been able to reproduce and sent it to the dev $$anonymous$$m. Since there's no date on when/if it will be fixed, I would still appreciate any workarounds that others have found.
Answer by soso · Dec 21, 2013 at 06:08 AM
using UnityEngine;
using System.Collections;
public class CopyPasteAct : MonoBehaviour
{
TextEditor mTe = null;
public static string copyPasteInfo = "";
void Awake()
{
mTe = new TextEditor();
}
void OnGUI()
{
Event e = Event.current;
if (e.type == EventType.KeyDown && e.control)
{
if (e.keyCode == KeyCode.C)
{
// Copy
mTe.content = new GUIContent(copyPasteInfo);
mTe.SelectAll();
mTe.Copy();
} else
if (e.keyCode == KeyCode.V)
{
// Paste
mTe.content.text = "";
mTe.Paste();
copyPasteInfo = mTe.content.text;
}
}
}
}
Thank you, @soso!
I just verified that this works in both the editor and webplayer for detecting the ctrl-v combo and retrieving the text.
It looks like they've partially addressed the issue - you can now detect the ctrl-v combo with Input.Get$$anonymous$$ey in both standalone and webplayer (according to my quick test). However, your solution is still the only one that seems to work in the editor, which is very nice.