Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by vahid62 · Apr 18, 2015 at 03:40 PM · textfieldcopypaste

Copy text in TextField to windows clipboard

I have a TextField and tow buttons.

One button for copying text of TextField to clipboard and one for paste from clipboard.

I have this code for copy but it doesn't work.

How can I do it in JS script?

Thanks.

 import System.Collections;
 var x : TextEditor;
 x.content.text=GUI.TextField(...);
 x.Copy();
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
6

Answer by Ryuuguu · Oct 16, 2015 at 07:54 AM

On OS X editor and OS X standalone GUIUtility.systemCopyBuffer is the clipboard. I believe this works on all platforms but I have not tested it yet. http://docs.unity3d.com/ScriptReference/GUIUtility-systemCopyBuffer.html so

 GUIUtility.systemCopyBuffer =  x.content.text

is all you need.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image c-war · Mar 07, 2017 at 06:05 AM 1
Share

I can verify that this also works in a Windows environment.

avatar image
0

Answer by Fornoreason1000 · May 26, 2015 at 08:37 AM

check this thread: http://stackoverflow.com/questions/899350/how-to-copy-the-contents-of-a-string-to-the-clipboard-in-c

Before you say it, I'm going to tell you that it doesn't matter that this in in C#. you can still use it in UnityScript (also known as Javascript) due to Unity using Mono which is pretty much .NET anyway.

well it doesn't matter what kinda of text you have as long as you can get a string value from it you can use. you can pretty much use the Clipboard class provided in the System.Windows namespace.

Here is a small example.

 import System.Collections;
 import System.Windows;
 
 function OnGUI() {
 
 if(GUI.Button(new Rect(50,50,50,50), "Copy") {
 Clipboard.SetText( x.content.text);
 
 }
 if(GUI.Button(new Rect(120,50,50,50), "Paste") {
 
  x.content.text = Clipboard.GetText();
 
 }
 }



For further reference on the clipboard class see here
Link: https://msdn.microsoft.com/en-us/library/System.Windows.Clipboard(v=vs.110).aspx

Hope it helps

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vahid62 · May 26, 2015 at 11:32 AM 0
Share

Thanks for your answer. It seems that System.Windows isn't supported in unity and I can't use it.

avatar image Fornoreason1000 · May 27, 2015 at 07:30 AM 0
Share

then the only other options is to use System.Windows.Forms, but if the namespace is "not supported"(which is pretty strange). then you literally cannot copy the text to the windows clipboard but there is a thread that has solves this.

http://answers.unity3d.com/questions/266244/how-can-i-add-copypaste-clipboard-support-to-my-ga.html

In this thread the answer ruses the Internal GUI clipboard, but the the second Answer has a possible solution in the asset store. i the asset store

I still find it very strange that System,Windows isn't supported, (probably because $$anonymous$$AC, Linux and all the other platforms can't use it).

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Stopping Copy/paste into Textfield. 3 Answers

Cannot copy, select or paste in TextField on Android 0 Answers

Objects in Play mode to Scene View 1 Answer

Copy/Paste Key Combos in Webplayer 1 Answer

How to enable copy/paste/delete for programatically selected objects? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges