Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

No system Clipboard access.

Discussion in 'WebGL' started by Deleted User, Mar 9, 2015.

  1. Deleted User

    Deleted User

    Guest

    Hi

    The Cut and Paste from the system clipboard does not seem to work?
    For instance open a word doc and copy some text, these items in the clipboard will not be pasted into a WebGL build, but can be pasted into a Web Player build(both the same project with a UI inputfield).

    None of the paste shortcuts work(Ctrl-V or Shift-ins) in a WebGL build, but Ctrl-V works in the Web Player.

    Is this a limitation within WebGL ? Anyone had this work for them ?
     
  2. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    There a several issues here.

    One is that Unity would not correctly detect and handle key combinations in text fields in WebGL. This was partially caused by issues in our input code and partially caused by issues in the input wrappers provided by the emscripten javascript runtime. Both have been fixed and this will work in 5.1, allowing Copy/Paste to work between text fields in Unity.

    The other part is allowing Copy/Paste to actually access the System clipboard to get text into or out of Unity from other windows/applications. Unfortunately, this is much more difficult as accessing the system clipboard is not generally possible from JavaScript due to security concerns (ie, to avoid a web page sniffing your credit card number from your clipboard). The only way to get this to work is to use an html text field instead of a unity one, which you can do from JavaScript code.
     
  3. hyperhippo

    hyperhippo

    Joined:
    Jan 16, 2014
    Posts:
    37
  4. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    @hyperhippo from your link:

    which basically gets us back to what I wrote:

    (Yes, it says that chrome also supports it on other DOM elements. I'm not sure that includes Canvas, and I don't want a single-browser solution).
     
  5. hyperhippo

    hyperhippo

    Joined:
    Jan 16, 2014
    Posts:
    37
    So my actual need for this is a bit different than the OPs.

    Our game http://www.kongregate.com/games/hyperhippogames/adventure-capitalist doesn't have Cloud storage for progress yet, even though it will sometime this summer/fall, until now, we used the system clipboard to allow players to "Export" the content of their PlayerPrefs to the clipboard, and email it to themselves, then login on another machine and "Import" from the clipboard.

    It was a quick and dirty way of doing things, we use a TextEditor from UnityEngine to set the content, call .SelectAll(), and then .Copy(); then to paste we just do new TextEditor(); and then .Paste(); and get the .content.text;

    Since Chrome is abandoning the webplayer this month and 60% of our paid web users come from Chrome, we're trying WebGL.

    So My users aren't actually needing a textfield to type into and we don't capture any keyboard input. So i'm assuming I need to create a hidden textfield much like they do here... https://www.lucidchart.com/techblog/2014/12/02/definitive-guide-copying-pasting-javascript/ i'm really not a javascript/html guy, just the guy that got stuck with porting our game to WebGL while the rest of the team is focused on our Mobile client which has a larger audience.

    Does this make any sense?
     
  6. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Yes, that makes sense. However, notice, that regardless of how you hack it with hidden text fields, you will only be able to use the clipboard when the user hits Cmd-C/Cmd-V. You cannot make a button which just fills data to the clipboard when the user clicks on it.
     
  7. gfoot

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    You can use a flash-based auto-clipboard mechanism for now. Chrome has a non-NPAPI flash implementation, and as far as I know Firefox is still allowing Flash for the time being.
     
  8. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    True - though kind of sadly ironic. To get rid of our plugin, the best thing you can do for copy and paste is to use another plugin (Flash).
     
  9. devluz

    devluz

    Joined:
    Aug 20, 2014
    Posts:
    65
    Old topic but: Is there is a solution to this now? How about to pop up an html overlay that shows the text if the user presses control + c in a input text box? I used prompt to implement it. Works fine to do copy and paste but sadly stalls the whole game. I guess an experienced web developer could get this done in a better way.
     
    prestonmatterport likes this.
  10. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Using an html text field overlay should work. How/why does it stall the game?
     
  11. devluz

    devluz

    Joined:
    Aug 20, 2014
    Posts:
    65
    I meant the "prompt()" method from js. I think it is normal that it stalls everything on the page. I will try a html overlay then. Would be great if Unity comes with something like that in the future.
     
  12. Freaking-Pingo

    Freaking-Pingo

    Joined:
    Aug 1, 2012
    Posts:
    310
    So based on the replies, I believe it is not possible to make use of the clipboard on iOS and Android then? We are currently sitting in a situation where we would like to utilize the clipboard in order for players to exchange LevelIDs.
     
  13. devluz

    devluz

    Joined:
    Aug 20, 2014
    Posts:
    65
    This is about browser games only. It sounds like you make unity apps for mobile devices? Mobile devices have usually the share functionality to do that. e.g. in Android you can use intends to share an id via facebook or any other messenger installed on the device.
     
  14. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    This looks to be broken even if you try to do an HTML overlay. Selecting text in that overlay is not possible, something about the initialization of the webgl unity is messing up the ability to select a group of text.

    If you notice on this page, you cannot select the title field (one word at a time works fine, but you can click and select a group of text), and this is the case for all html text you put on the page (in chrome at least). I ended up implementing it in a sort of hacky way by popping up an alert box with the text to select....
     
  15. devluz

    devluz

    Joined:
    Aug 20, 2014
    Posts:
    65
    This is probably the default webgl template. Try removing
    ::-moz-selection
    ::selection
    from the style.css

    Edit: just had a look at the website. Doesn't look like the default at all ;) but could it be that those css commands get in somewhere? If I remove them in my template I can select and copy / paste

    edit: looks like you have something like this: ;-webkit-user-select:none; in your css
     
    Last edited: Nov 12, 2015
  16. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
  17. TalhaDX

    TalhaDX

    Joined:
    Feb 2, 2013
    Posts:
    94
    how to copy text to clipboard in mobile android
     
  18. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    This forum is for Unity WebGL. Please ask in the iOS and/or Android forums.
     
    TalhaDX likes this.
  19. vizgl

    vizgl

    Joined:
    Nov 4, 2014
    Posts:
    61
    Hi to all,
    I have solution, how to copy from WebGL app. But this solution good only for debugging.

    Code (csharp):
    1.  
    2.  if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.C))
    3.         Application.ExternalCall("console.log", "text to copy");
    4.  
    Now, you can find your texts in the JS console in your browser.
     
  20. fwalkerCirca

    fwalkerCirca

    Joined:
    Apr 10, 2017
    Posts:
    57
    So it is the end of 2017 any advancements on this front? Or are we stuck with a text field overlay?
     
  21. KHAKAN

    KHAKAN

    Joined:
    Apr 3, 2013
    Posts:
    1
    Are there any developments?
     
  22. sumpfkraut

    sumpfkraut

    Joined:
    Jan 18, 2013
    Posts:
    241
  23. Karsnen_2

    Karsnen_2

    Joined:
    Nov 28, 2011
    Posts:
    89
    Code (CSharp):
    1.    internal static string Clipboard
    2.         {//https://flystone.tistory.com/138
    3.             get
    4.             {
    5.                 TextEditor _textEditor = new TextEditor();
    6.                 _textEditor.Paste();
    7.                 return _textEditor.text;
    8.             }
    9.             set
    10.             {
    11.                 TextEditor _textEditor = new TextEditor
    12.                 {text = value};
    13.  
    14.                 _textEditor.OnFocus();
    15.                 _textEditor.Copy();
    16.             }
    17.         }