listen to clipboard changes, check ownership?

前端 未结 3 1740
北海茫月
北海茫月 2020-12-06 13:33

I want to be notified if a string is copied to the system clipboard. When a new string is copied from the same source application, the FlavorListener won\'t get an event. To

3条回答
  •  孤城傲影
    2020-12-06 14:17

    The previous answer is close to be working.

    The real cure is to instead just monitor the event of ownership change. By the monitor's occupying the clipboard as owner when monitoring the clipboard, so when any application changes the clipboard, the ownership would change, so this would reliably indicate the clipboard content change. However, this approach must have sufficient wait to work, (200 ms was found to be working) after an ownership change event before accessing the clipboard and re-occupying the clipboard.

    This solution was provided and proved to be working by marc weber at http://www.coderanch.com/t/377833/java/java/listen-clipboard

    I have verified for my purpose. If needed, I can post the solution here.

    Yu

提交回复
热议问题