Search Unity

Pasting into a TextField?

Discussion in 'Immediate Mode GUI (IMGUI)' started by seon, Nov 10, 2007.

  1. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Is there no way to enable pasting into a TextField?

    We want our customers to be able to paste their serial numbers for our games into our in-game registration system, but it seems Unity doesn't supporting pasting of text into the TextField.

    Is there something we can do?
     
  2. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    My posterior is feeling gregarious today, and it says: maybe you could write a plugin that fetches the contents of the clipboard/Windows equivalent?
     
  3. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Haha... yep, um, and while I am at it.. I think I might write my own Unity->PS3 exporter while I am at it :)
     
  4. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    I bet it would be much easier than you think. :wink:

    (Said pot to kettle.)
     
  5. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    It might be a bit harder than expected. Access to the Clipboard in .Net is via System.Windows.Forms.Clipboard - and the S.Windows namespace is not supported. The Gtk namespace has the equivalent cross platform clipboard functions, but its not accessible in Unity AFAIK.

    So, the only way I can see to get to the clipboard is to have a DLL on windows that talks to Win32's OpenClipboard and GetClipboardData. On Mac, you would need the same in a bundle.

    If anyone else knows another way, I'd love to hear it.

    Seon - would love to know when your PS3 exporter is ready! ;)
     
  6. thylaxene

    thylaxene

    Joined:
    Oct 10, 2005
    Posts:
    716
    On the Mac you can use the terminal. Using these commands:

    Code (csharp):
    1. pbcopy < filename
    2. #copies contents of a text, rtf, or eps file to the clipboard
    3.  
    4. pbpaste
    5. #pastes content of clipboard to stdout
    6.  
    I couldn't find any equivalent on the Windows side unfortunately... well nothing that doesn't require the end user to install a little helper app called "Clip.exe" that apparently comes installed with Windows 2003 Server. Which allows you to pipe content from the commandline both directions.

    So I guess it's time for a plugin in...

    Cheers.
     
  7. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    Hey Seon, I got the clipboard function working a in C# class and spat it out as a DLL assembly - it grabs the text in the system clipboard and returns it as a string.

    I'm stuck on the integration part - can't seem to get it running Unity.
    So my question (to anyone) - is there anything special we need to do in a C# assembly to make a static function accessible in Unity?

    I think I'm using P-Invoke correctly and I've used other DLLs in Unity before. Problem is likely in the way I've written the ClipboardWrapper DLL - or I'm doing something incredibly asinine, the latter being more likely.

    Thx
    shaun
     
  8. thylaxene

    thylaxene

    Joined:
    Oct 10, 2005
    Posts:
    716
    did you get it working for both platforms or just for Windows?

    Last time I did anything with a .Net DLL all you had to do was put it in the plugins directory of your assets and call it like any other .cs or .js file.

    Cheers.
     
  9. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    Only for Windows at the moment.
    I've used C++ DLL's without any troubles, but im not sure how we handle .Net DLLs - If we call them directly (in which they run under Mono) or use PInvoke.
     
  10. thylaxene

    thylaxene

    Joined:
    Oct 10, 2005
    Posts:
    716
    I had success calling them directly if they are .Net DLLs.

    Cheers.
     
  11. thylaxene

    thylaxene

    Joined:
    Oct 10, 2005
    Posts:
    716
    OK here is my example of doing it in OSX using the shell. It's not perfect solution by a long shot. Also I can't seem to get the combos working of "Command-v". Also how does one get focus on a textfield and target that textfield's string variable?

    Cheers.
     

    Attached Files:

  12. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    Nice one - I like the paste icons, reminds me of the good old days ;)

    As for getting the active text controls maybe GUIUtility.keyboardControl could be useful as well as GUIUtility.GetControlID.

    What I was thinking is that whenever the control is active, it checks a 'wasCtrlVPressed' global variable - you press Ctrl-V and it grabs whatever is in the clipboard and merges it with the textfield's value.
     
  13. podperson

    podperson

    Joined:
    Jun 6, 2006
    Posts:
    1,371
    I'd like to see some degree of proper clipboard support in Unity (runtime) as a whole. A lot of folks may not want to write games...