Text selection in Rust

Hi

I am a newbie to rust and thinking of building a small desktop app (as an exercise) that works like a Clipboard in Windows.

As a first step, I am trying to understand, how I can recognize a text selection in Rust.

Any suggestion is much appreciated

Polohise if this is a wrong forum to ask.

Thanks

Hi @jeeva

If you want to access the system clipboard, take a look at this project:

aweinstock314/rust-clipboard: System Clipboard interfacing library in Rust (github.com)

If you want to make a window program, you can try “Tauri”

Build smaller, faster, and more secure desktop applications with a web frontend | Tauri Apps

hope it helps you :grinning:

1 Like

I'm not sure what are you trying to achieve?

Are you trying to recognize text selection in other application, then get the text when certain hotkey (like Ctrl + C) is pressed? If that's the goal, then it's not achievable. Clipboard works by the application actively calling Windows API related to the clipboard. It's not based on some magic text selection detection.

If you are not trying to implement this behavior, then you might need to elaborate your goal with more detail.

1 Like

If you do want to recognize when the selection changes in some other application for summer reason, your best bet is probably using accessibility apis: but good God those apis are terrifying on windows natively. I can't see any accessibility client wrapping crates either (accesskit is for accessibility providers), so going raw windows crate might your best option, but don't expect it to be easy.

2 Likes

thanks, FakeRick, ya the rust clipboard looks something familiar. Thanks for the suggestion.

Yes, you have got my context and you are spot on about the Windows API. I read through the API here
https://learn.microsoft.com/en-us/windows/win32/dataxchg/clipboard and then realised it is not possible what i was looking.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.