Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
On Clipboard Set Event
Hi, Is there a way to trigger an event when the clipboard is written to?

I am using google Maps and when a coordinate is clicked using the right click context menu, the coordinates will copy to the clipboard. I can use a timer to check for a change in windows clipboard but this is problematic as it will run system wide rather than at a specific event

To note: Edge will pop up 'Copied to clipboard' when data is written to the clipboard.

I'm not aware of any specific functionality for this exposed by WebView2.

In your case I would be looking into trying to do this from javascript.
This link is a starting point for that:

So add the event-listener via ExecuteScript with code like:
function myOnCopyEvent() {
  console.log("Someone used Ctrl+C");
and then add the event listener like:
document.querySelector("body").addEventListener("copy", myOnCopyEvent);

I just tested that in MS Edge developer toolbox and it did indeed display the console log message.
FWIW, I'm using the html "body" selector here, but if you have something more specific then that should work as well.

Instead of writing to the console log you could then send a webmessage (see the webmessage demo in VB6 that comes with AntView) to trigger an event.

Based on that event triggering you can then read the clipboard from your application.

Forum Jump:

Users browsing this thread: 1 Guest(s)