Open ghost opened 3 years ago
Thanks. Will test this out...
Forgot to mention. The same thing happens in your NetCoreWinForms sample. Put a breakpoint on:
if (e.ContentType == WK.Libraries.SharpClipboardNS.SharpClipboard.ContentTypes.Text)
copy URL in Chrome and it should trigger twice. I'll see if I can figure something out...
Edit: Not completely sure, but other implementations struggle with the same, so I wonder if Chrome is really copying things twice. I find this strange as I thought Chrome couldn't influence the clipboard if I right click in the address bar and copy the value.... Other implementations show me that it first copies the url without "http" and then with "http"....
Anyways, one workaround is to just use a timer and ignore event that come in a close succession.
That's quite a strange behaviour from Chrome. You're actually right about the copy issue. The Chrome address bar runs a script that does parse URLs on update and special events, e.g after copying/pasting.
I'll need to test this further and probably provide a custom implementation or workaround that uniquely works with chrome. For now, try using the argument e.SourceApplication.Name
in the ClipboardChanged
event to determine if the active application being copied from is Chrome (chrome.exe) then capture the first copy instance only and ignore the second.
Yeah, I saw the same thing happening... I've solved with a timer as a workaround for now. I check that the content is different and reset the "cache" when the timer elapses. Works perfectly for my case. :)
private string clipboardCache = null;
private readonly Timer clipboardTimer = new Timer(5000);
...
private void ClipboardTimer_Elapsed(object sender, ElapsedEventArgs e)
{
// Remove cache when timer elapses
clipboardCache = null;
clipboardTimer.Stop();
}
// Copied value is not currently in cache
if (e.Content.ToString() != clipboardCache)
{
// Update cache
clipboardCache = e.Content.ToString();
clipboardTimer.Start();
// Only handle valid links
....
}
This same issue happens with the Windows 10 screen snip.
Click on actions/notifications. Click screen snip, select a region. Clipboard change is triggered twice.
Thanks
It's OS Trouble
search google "clipboard event twice" or "clipboard event Echo"
if Fire Clipboard.Settext in SharpClipboard.Tests.Winform it's Fire 2 time ChangedEvent.
also every Trouble Clear.
windows act many check clipboard point. But number 2 is Any trouble Solve.
sorry about my english not good
the same issue is happening on copying from firefox.
I discovered the same problem happening even on XP :)
And another problem, with this library, it detects images "twice" which were set by My.Computer.ClipBoard.SetImage method of VB.NET. There is a bug. And also, I couldn't find a method to set image natively within this library there.
I solved the problem with:
if (!IsTriggered)
IsTriggered = true;
await Task.Delay(20);
Line 20 andIsTriggered = false;
BTW:
In case of Chromium links I get them including the description as TextDataFormat.Html
.
I tested copying from the address bar of Edge, Chrome and Opera. With Chrome and Opera my ClipboardChanged event is called (triggered or invoked, whatever) twice. With Edge it is called 3 times.
Anyone familiar with the GetClipboardSequenceNumber function? Perhaps I misunderstand what that does but it seems to solve the problem. The WinAPI function can be used stand-alone.
I notice that copying the URL from Chrome 84.0.4147.125 triggers the detection twice. Seems to work as intended in every other occasion.