By popular demand: a plugin to support copy/paste, integrating with the Windows clipboard!
This plugin allows you to copy text from other applications and paste it into an AGS game, or vice versa.
The plugin provides two methods:
bool Clipboard.CopyText(String copyString);
String Clipboard.PasteText();
Calling Clipboard.CopyText(copyString) will put copyString on the Windows clipboard (returning true if successful), accessible to other applications. Calling Clipboard.PasteText() returns the current text content of the Windows clipboard as a String (or null if none) that you can use in-game. Pretty simple.
As with all AGS engine plugins, you have to place the .dll file in the AGS engine folder, then activate it in the IDE from the project tree before you can use the methods. It should be unnecessary to state, but for the record: the game must be designed and created to use the plugin, you can't just drop it into the folder of a finished game and expect it to do anything.
This is my first AGS plugin, and my first C++ project in many years. It works on my machine, but I'm not 100% sure it will work on every Windows machine â€" in particular on older Windows versions. If you could try the demo and let me know if you experience any problems, I'd appreciate it.
The code is available on Github (https://github.com/messengerbag/Clipboard). (In the demo game, the example of how to use it is in TextField (https://github.com/messengerbag/Clipboard/blob/master/Clipboard%20Demo/TextField.asc).HandleKeyPress(), starting on line 538.)
Download Clipboard plugin (https://github.com/messengerbag/Clipboard/releases/download/v0.4/AgsClipboard.dll)
Download Clipboard demo (https://github.com/messengerbag/Clipboard/releases/download/v0.4/Clipboard.Demo.zip)
Change log:
v0.4 (https://github.com/messengerbag/Clipboard/releases/tag/v0.4)
-Initial release (untested except for on my own machine)
I've just had a quick go with the demo and it works fine for me on Windows 10. :)
On Windows 7 it's working like a charm! Great work as usual Snarky!
Some extra notes aside: Should Ctrl+Z remove the previous paste text and Ctrl+Y add the latest text copied?
Quote from: Riaise on Fri 30/03/2018 15:05:33
I've just had a quick go with the demo and it works fine for me on Windows 10. :)
Quote from: Vincent on Fri 30/03/2018 15:31:05
On Windows 7 it's working like a charm!
Good! I'm on Win10, so I thought that would probably work, but I'm very happy to hear it's working on Windows 7 as well. Hopefully that means that it's not terribly dependent on the Windows version. Thanks for testing!
QuoteGreat work as usual Snarky!
Some extra notes aside: Should Ctrl+Z remove the previous paste text and Ctrl+Y add the latest text copied?
Thanks. Sure, undo/history would be useful to have, but it wouldn't be part of the plugin, but rather something you implement in your game logic. I'll think about adding it to the TextField module.
You are welcome Snarky!
Quote from: Snarky on Fri 30/03/2018 15:41:18
Thanks. Sure, undo/history would be useful to have, but it wouldn't be part of the plugin, but rather something you implement in your game logic. I'll think about adding it to the TextField module.
In fact, I was thinking that it could be implemented in the TextField module as well instead of in the plugin itself after I had a look into the code on Github.
Sorry if it wasn't clear, but I was talking about your TextField module. Give people a little credit, Snarky.
Fair enough. I've moved your post over to the TextField module thread.
A bite late, but I just saw this and ;-D
This is SO COOL. And would have been super useful on my current project (no more copying debug info manually!). Will definitely use it in the future.
Hmm. Testing it on a relatively untouched Win10 VM, this plugin turns out to have a dependency on some platform dll from Visual Studio that isn't universally deployed: probably (some version of) msvcp or msvcr. Without it, any game that includes the plugin will fail to run. I'll investigate more to identify the dependency and see if it can be bundled with the plugin.
Hi !
I found this nice plugin, but my question is : will it limits the possibilities to play my game using this plugin if the game is played on another OS than windows ?
I mean : MAC users or Linux users could play the game ? Or it will not run ?
The commands to copy/paste are not essential for the game, it's just a "luxure" for those who could use it (windows players, so).
Yes, the plugin currently only works on Windows, and games compiled with it won't run on Mac/Linux. However, if you take a little bit of care, you can simply build it once for Windows, disable the plugin, and build it again for other platforms. For this to work, you should wrap all plugin calls within #ifdef CLIPBOARD_PLUGIN conditions, like so:
#ifdef CLIPBOARD_PLUGIN
String s = Clipboard.PasteText();
if(!String.IsNullOrEmpty(s))
{
lblContent.Text = s;
return true;
}
else return false;
#endif
#ifndef CLIPBOARD_PLUGIN
return false;
#endif
Thanks Snarky for the help !
Could you please explain me how to install your plugin in AGS, so ? I use 3.5.0
Check out the manual, "Other features | Plugins."
Hi Snarky !
Finally, I'm using your plugin, and it works perfectly on windows 10 with AGS 3.6.1 :)
thanks a lot for it !
Hi Snarky,
I encountered one problem with your module. Perhaps because I'm french and I use specific symbols that are not english-friendly (damned french people...).
If I copy/paste a text from windows (like a sentence in a notepad's file) to my game (using your module), I have seen that, depending on the font used when I paste : the "é" becomes "dnx", or the "é" becomes "^". I have to precise that the font used has its "é" symbol, so no problem to use it normally.
Do you know if it comes from your module ? Or perhaps from AGS ? I use the latest things related to scripts, like the on_textinput functions and related options.
I have not tested with other symbols like "è" "à" "ô" yet.
@Baguettator, I'm fairly sure the plugin predates Unicode support in AGS. I don't at this point know what determines how non-ASCII characters appear; I have a vague sense that it's based on the computer's language setting (codepage).
The robust solution would be an updated plugin that worked with wstrings.
Quote from: Snarky on Sun 26/05/2024 02:43:30@Baguettator, I'm fairly sure the plugin predates Unicode support in AGS. I don't at this point know what determines how non-ASCII characters appear; I have a vague sense that it's based on the computer's language setting (codepage).
The robust solution would be an updated plugin that worked with wstrings.
If it uses ANSI functions from WinAPI, then all text is of course also stored as ANSI.
The workaround could be to add a conversion to UTF-8 strings into this plugin. Examples of this may be found in both the AGS Editor and Engine code (iirc),
This way it might also keep plugin working in both ANSI and Unicode modes, but there has to be a switch in plugin's API, or maybe plugin can get this info from the engine somehow...
Thanks for your answer ! The thing now is : will this plugin be updated..? ;)
Quote from: Crimson Wizard on Sun 26/05/2024 03:00:25If it uses ANSI functions from WinAPI, then all text is of course also stored as ANSI.
The workaround could be to add a conversion to UTF-8 strings into this plugin. Examples of this may be found in both the AGS Editor and Engine code (iirc),
This way it might also keep plugin working in both ANSI and Unicode modes, but there has to be a switch in plugin's API, or maybe plugin can get this info from the engine somehow...
The plugin uses the WinAPI functions
IsClipBoardFormatAvailable(CF_TEXT),
GetClipBoardData(CF_TEXT), and
SetClipBoardData(CF_TEXT, HGLOBAL hglb), where
CF_TEXT is a constant that specifies an ANSI string (and
hglb is a handle to the raw string data). There is another constant,
CF_UNICODETEXT, that would specify Unicode format.
It provides the AGS functions
void ClipBoardCopyText(String) and
String Clipboard.PasteText(), and assumes that a String is a char*. It relies on
engine->CreateScriptString(lptstr) (which hopefully shares this assumption).
Converting the strings to and from Unicode falls outside the plugin scope, I think (I have some notion that the Windows clipboard itself is responsible for converting between compatible formats), but the plugin might either provide two versions of the Copy/Paste functions, or if there is an API for it, detect whether AGS is using Unicode mode.
Quote from: Baguettator on Sun 26/05/2024 05:33:35Thanks for your answer ! The thing now is : will this plugin be updated..? ;)
I mean, it's open source, so anyone can update it. I'm not planning to do so at the moment, mainly because I don't think I have a computer with Visual Studio installed.
Edit: Also, for reference in this thread, on Discord
@eri0o shared a link to a project for multi-platform clipboard support, https://github.com/dacap/clip, and noted that the ImGui plugin (https://www.adventuregamestudio.co.uk/forums/modules-plugins-tools/plugin-agsimgui-0-3-0-build-guis-easily-for-debug-purposes!/) has some level of clipboard support (https://github.com/ericoporto/agsimgui/blob/357a5fd4723b4b2a21c583ed1879686c6d99e7b8/agsimgui/agsimgui.cpp#L1260).
Ow... :~(
If someone is going to update it, I will be grateful :)
Quote from: Snarky on Sun 26/05/2024 06:33:50Converting the strings to and from Unicode falls outside the plugin scope, I think (I have some notion that the Windows clipboard itself is responsible for converting between compatible formats), but the plugin might either provide two versions of the Copy/Paste functions, or if there is an API for it, detect whether AGS is using Unicode mode.
I mean, you would have to convert to UTF-8 strings anyway if you want engine to understand your text, because widestring WinAPI uses Unicode-16 format.
In WinAPI utf-8 strings are called "multibyte" strings, and it provides conversion functions for getting utf-8 from widestrings.
EDIT: alternatively, there's a platform-independent way, like we have in the engine:
https://github.com/adventuregamestudio/ags/blob/860a4d1319ba76cfba1b3fdb52fcc64e1fe92d18/Common/util/string_utils.cpp#L317-L327
https://github.com/adventuregamestudio/ags/blob/860a4d1319ba76cfba1b3fdb52fcc64e1fe92d18/Common/util/utf8.h#L86
Hi Snarky, do you plan to update your module with crossplatform compatibility and UTF-8 strings ? It would help me a lot... But I know it's need of time and will to do that, so don't worry :)
I would like to at some point, but I have no immediate plans to do so.