ClipThat 0.1.1
dotnet add package ClipThat --version 0.1.1
NuGet\Install-Package ClipThat -Version 0.1.1
<PackageReference Include="ClipThat" Version="0.1.1" />
<PackageVersion Include="ClipThat" Version="0.1.1" />
<PackageReference Include="ClipThat" />
paket add ClipThat --version 0.1.1
#r "nuget: ClipThat, 0.1.1"
#addin nuget:?package=ClipThat&version=0.1.1
#tool nuget:?package=ClipThat&version=0.1.1
<img src="./docs/clipthat.png" alt="drawing" width="200"/>
ClipThat
A clipboard monitoring tool written in RUST linked to C# for cross platform clipboard monitoring.
<img src="./docs/meme.png" alt="drawing" width="600"/>
RUST
./lib
Why rust, well there is simply NO good way to handle this in dotnet using both linux and windows. 'that i could find anyway'
The clipboard library is a background thread that monitors your clipboard, as text is copied it delgates this text to a function pointer. This function is linked to our C# library.
Build Steps
- Install RUST https://www.rust-lang.org/learn/get-started
- Navigate to the
./lib/clipboard
directory - Execute
cargo build --release
to generate aclipthat_clipboard.dll
located in the./clipboard/target/release
directory
Once compiled the library should be added to the C# code as an embedded resource and dynamically linked. See the C# solution for details.
note you will not be able to build the CSharp librarys until the RUST binary is created
CSHARP
./pkg
Assuming you have complied the Rust library you dontnet solution should have no errors.
The ClipThat
project is a library that gets packed to a nuget. This library is fairly simply and just links into the RUST binary.
The RUST library is added to the project with a relative path so its recreated everytime the RUST project is compiled.
An example console application have been provided ClipThat.Example
Usage
Create a new clipboard using the ClipboardFactory
. Currently there are two different clipboards,
one running a managed thread in Rust and another that runs on a CSharp thread. While the Rust thread is faster and more efficient
it can produce exceptions when invoked from certain contexts.
Create a new Clipboard
object providing a Action<string, Exception>
used to delegate any errors to the consumer
var clipboard = new ClipboardFactory()
.WithForegroundProcessing(TimeSpan.FromMilliseconds(200))
.Build((method, error) =>
{
Console.WriteLine($"Error From {method}: {error?.Message}");
});
or
var clipboard = new ClipboardFactory()
.WithBackgroundProcessing()
.Build((method, error) =>
{
Console.WriteLine($"Error From {method}: {error?.Message}");
});
The clipboard class is Disposable
so you can wrap it inside a using state to stop monitoring the clipboard.
using var clipboard = new ClipboardFactory()
.WithForegroundProcessing(TimeSpan.FromMilliseconds(200))
.Build();
Once created the clipboard.StartMonitoringClipboard(textReceived => {});
method should be called to start watching for changes.
var clipboard = new Clipboard((message, error) =>
{
// Process Error Here
});
clipboard.StartMonitoringClipboard(text =>
{
Console.WriteLine($"CLIPBOARD TEXT RX: \n{text}");
});
You can also send text to the clipboard.
Please note you should be carful based on the useage,
sending text to the clipboard could also invokde the monriting and execute the text recevied callback.
This could create an endless loop if not handled
clipboard.SetClipboardText(data);
When the monitor is disposed the callback with stop sending data to the application.
clipboard.Dispose();
You can also manually poll the clipboard without starting the monitor.
var clipboard = new Clipboard((message, error) =>
{
// Process Error Here
});
var polledText = clipboard.PollClipboard();
if (!string.IsNullOrEmpty(polledText))
{
Console.WriteLine($"Polled Keyboard Text: \n", polledText);
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.