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.
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!
On the Mac you can use the terminal. Using these commands:
pbcopy < filename
#copies contents of a text, rtf, or eps file to the clipboard
pbpaste
#pastes content of clipboard to stdout
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.
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.
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.
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.
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?
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.