Posts: 1,031
Threads: 246
Joined: Jul 2022
The following code can put a single image(A.png) to the clipboard,
but is it possible to put multiple images(A.png; B.png; C.png) at once?
I now understand that simulating manual operations is achievable:
1. Select three images: A.png, B.png, and C.png.
2. Press Ctrl+C.
3. Act elm.
4. Press Ctrl+V.
var img = Image.FromFile(folders.Desktop+"A.png");
var dimg = new clipboardData().AddImage(img);
//act elm
clipboard.pasteData(dimg);
Posts: 12,073
Threads: 140
Joined: Dec 2002
04-04-2024, 04:28 AM
(This post was last modified: 04-04-2024, 04:29 AM by Gintaras.)
Quote:Select three images
Select 3 files in File Explorer?
Exists standard file formats to store multiple file paths in the clipboard, but not to store multiple image data. If the target program uses its own format, you need to know it and create data in that format.
Posts: 1,031
Threads: 246
Joined: Jul 2022
04-04-2024, 08:43 AM
(This post was last modified: 04-04-2024, 08:45 AM by Davider.)
Quote:Select 3 files in File Explorer?
Yes
I want to send multiple pictures using the clipboard because sometimes I want to execute this operation asynchronously. If I use simulated execution, the operations in two threads will conflict.
Additionally, I would like to know how to avoid such conflicts? For example, when multiple mouse operations are happening simultaneously, how can one operation be prioritized to complete first?
Posts: 12,073
Threads: 140
Joined: Dec 2002
var dimg = new clipboardData().AddFiles(path1, path2, path3);
dimg.SetClipboard();
To avoid conflicts when using multiple threads, I usually use the C#
lock keyword. Don't know how to prioritize.
Posts: 1,031
Threads: 246
Joined: Jul 2022
04-04-2024, 09:49 AM
(This post was last modified: 04-04-2024, 09:50 AM by Davider.)
Useful, thank you.
The prioritization handling is interesting;
it can successfully execute as long as the mouse or keyboard are not being used simultaneously. I'm currently unable to find a solution.
Posts: 1,031
Threads: 246
Joined: Jul 2022
The `
GetFiles` function in Code1 does not support regular expressions. Therefore, in Code2, I used the `
enumFiles` function from LA, which seems a bit complex. It would be very convenient to have an extension method for `
GetFiles` that supports regular expressions.
Code1:
var ar1 = Directory.GetFiles(dirPath, "AZ?.jpeg"); //files as string[]
print.it(ar1);
var dimg = new clipboardData().AddFiles(ar1);
Code2:
var a = filesystem.enumFiles(dirPath, "**m AZ?.jpeg||SX?.jpeg").ToArray();
List<string> paths = new List<string>();
foreach (var f in a) {
var path = f.FullPath;
print.it(path);
}
string[] ar1 = paths.ToArray();
var dimg = new clipboardData().AddFiles(ar1);
Posts: 12,073
Threads: 140
Joined: Dec 2002
In tool Get files in folder check Select path.
Posts: 1,031
Threads: 246
Joined: Jul 2022
Thank you, the generated code is excellent.
var ar1 = filesystem.enumFiles(dirPath, "**m AZ?.jpeg||SX?.jpeg")
.Select(o => o.FullPath)
.ToArray();