Copy and Paste on Win32 Desktop / OSX Builds

Hi,

I’ve used the Pasteboard plugin before for iOS to allow users to copy and paste text into our apps.

Does anyone know if there is a way to achieve the same thing for Desktop builds?

Pasteboard - https://docs.coronalabs.com/plugin/pasteboard/ - only supports iOS and Android.

Thanks,

Ian

Hi Ian,

Here is a pasteboard module that works on OS X, but I don’t believe it works on Windows. Hope this helps! The zip file includes a main.lua that demonstrates in a very simple way.

I’ve been able in the past to achieve this on Windows using something like

local clip = io.popen("clip") if clip then clip:write(MyText) -- For writing, but reading would be local text = clip:read() clip:close() end

but in testing it just now io.popen appears to be “unsupported”. It seems to come and go. (OS X still allows it, on the other hand.)

On Windows you could use the clipboard, some examples of which can be found here: How to copy string to clipboard in C?

Original link to code adapted by schroederapps : OSX Pasteboard

More conversation about that code that I modified (I think my modifications made their way into the gist): https://forums.coronalabs.com/topic/59349-pasteboard-for-osx/

@schroederapps yes both your and Perrys modifications made it into the gist.

Thanks - I will look into this. It’s mainly Win32 I wanted it for as I want to let people paste a serial number in to verify their purchase, which I don’t need to do on OSX.

Will report back as to how I get on.

Cheers.

No luck with the above on Win32 - works brilliantly on other platforms though as expected.

Unfortunately I don’t have the expertise with C / incorporating C code into a Corona project to understand how to incorporate the info StarCrunch posted - https://stackoverflow.com/questions/1264137/how-to-copy-string-to-clipboard-in-c

If anyone from Corona has any idea on how best to achieve pasting on Win32 builds that would be great. Is there a way?

Thanks.

The commands are different on Windows, but it might very well be possible with os.execute() rather than io.popen(), e.g. see this page.

About the link, sorry, I tend to translate “Enterprise” as “knows C / C++”.  :smiley:

Have a go with this: clipboard plugin

You can drop it into the …/AppData/Roaming/Corona Labs/Corona Simulator/Plugins/plugin (whew!) directory to use in the simulator. Most of that you can reach by doing File->Open Project Sandbox  and then switching from AppData/Local to AppData/Roaming. To use more generally it might be enough to just add a plugin directory to your program and dump it there.

Anyhow, this is just cobbled together from a couple SO posts, that one I showed you and one other.

Usage:

local clipboard = require("plugin.clipboard") local ok, text = clipboard.GetText() if ok then print("Clipboard text:", text) end ok = clipboard.SetText("BLARGH!") if not ok then print("Something went wrong!") else print("Huzzah!") end

This is all of forty minutes of putzing around, so obviously not thoroughly tested.  :slight_smile:

Wow - thank you. Really appreciate this. I’ll dig into it and let you know how I get on.

Thanks,

Ian

This works perfectly in the simulator - thanks so much for taking the time to put it together. Really appreciate it.

To use more generally it might be enough to just add a  plugin  directory to your program and dump it there.

Unfortunately this doesn’t seem to be the case. I can’t get it working once published out for Win32 - it doesn’t seem to be able to find the plugin. I’ve included a plugin folder in my project but no joy…

This page talks about plugins in Enterprise and I definitely have Enterprise running on my Windows machine so it seems like it *should* work without needing to do anything to build.settings but I’m getting errors.

https://coronalabs.com/blog/2015/03/10/tutorial-corona-sdk-to-corona-enterprise/

Will keep digging.

Cheers,

Ian

Ah, nuts.

For what it’s worth, I have several binary modules in the works, and in a couple cases this very sort of issue is my bottleneck. At the moment I’m running into it with iOS, once I moved off-(Corona) simulator, but would have soon run afoul of desktop executables. :) Since I’ll already be doing this kind of thing, I could add this one to the queue, work out the details, and submit it formally. It might be a while, though.

If your situation is rather urgent, you’re more than welcome to submit the plugin yourself. Most of the info should be here. You’d easily be doing just as much if not more work than I, getting all the details in order.  :) If you do go this route, perhaps just point to this discussion and name me as a collaborator. As I alluded earlier re. io.open , I already have use cases for this, so I would also have a vested interest in quashing any bugs that arise.

After doing a Win32 build, copy the “clipboard.dll” file to your Win32 app’s directory; next to your *.exe and all of the other *.dll files.  That should make it work.  This is because, on Windows, the application directory is always the first directory in the DLL lookup path.

Side Note:

Corona Simulator app builds can only include plugins that have been uploaded to our server and referenced in your “build.settings” file.  So, plugins you have made on your own have to be added manually.

Thanks guys.

Got it working by placing the whole “plugin” directory in that folder alongside the .exe. It works perfectly.

Obviously would be great to get this submitted as a plugin. I’ll have a look at the guide. Am I right in thinking just submitting a Windows version wouldn’t be enough though and that other platforms need to be supported too?

StarCrunch - really appreciate you taking the time to do this. Massive thanks.

StarCrunch…

Do you have the source file(s) for the DLL that I can take a look at please?

Thanks,

Ian

Hi Ian. Glad to hear it.

The two files you should need are in the zip.

The setup would basically go as Joshua’s post describes here.

I’m not even sure there’d be anything to support on non-Windows platforms, really. Isn’t that what the pasteboard does?  :slight_smile:

Ah okay - the 2 files in the zip make up the dll? Great.

Yes - that’s what pasteboard does - I was just trying to clarify if Corona allows the submission of a plugin that only supports one platform. I’m sure I read somewhere that it at least needed to support OSX too…

Thanks.

I think I need this feature to backup/restore saves for my games.

Any ETA - when it will be implemented to corona it self even as plugin? =)

Hi Ian,

Here is a pasteboard module that works on OS X, but I don’t believe it works on Windows. Hope this helps! The zip file includes a main.lua that demonstrates in a very simple way.

I’ve been able in the past to achieve this on Windows using something like

local clip = io.popen("clip") if clip then clip:write(MyText) -- For writing, but reading would be local text = clip:read() clip:close() end

but in testing it just now io.popen appears to be “unsupported”. It seems to come and go. (OS X still allows it, on the other hand.)

On Windows you could use the clipboard, some examples of which can be found here: How to copy string to clipboard in C?

Original link to code adapted by schroederapps : OSX Pasteboard

More conversation about that code that I modified (I think my modifications made their way into the gist): https://forums.coronalabs.com/topic/59349-pasteboard-for-osx/