arboard icon indicating copy to clipboard operation
arboard copied to clipboard

Handle clipboard change event?

Open bit-ranger opened this issue 2 years ago • 5 comments

Is there any way to handle clipboard change event?

bit-ranger avatar Sep 03 '22 13:09 bit-ranger

Hey there, @bit-ranger. AFAIK, clipboard change events are a feature of window managers and not raw clipboard accesses. Windows, for example, has AddClipboardFormatListener that can fire WM events for you, but I don't know if its usable in the context of a CLI application off the top of my head.

complexspaces avatar Sep 16 '22 17:09 complexspaces

its posible https://crates.io/crates/clipboard-master

0-don avatar Jun 08 '23 19:06 0-don

@complexspaces Can i start a thread monitor the clipboard.get_text() change or not?

huangganggui avatar Jun 04 '24 09:06 huangganggui

@huangganggui No, that won't work like you want. get_text() does not block waiting for changes, it will either return the current clipboard contents or an error if nothing is available.

In theory: you could read the current clipboard value, poll the clipboard every second in a thread, and see if the value has changed but that's pretty inefficient.

complexspaces avatar Jun 04 '24 16:06 complexspaces

@complexspaces Nice! I will try poll the clipboard every 0.1s in a thread. In my case, efficiency maybe not such important. Thanks a lot.

huangganggui avatar Jun 05 '24 03:06 huangganggui