private IntPtr WinProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { switch (msg) { case Win32.WmChangecbchain: if (wParam == hWndNextViewer) { hWndNextViewer = lParam; //clipboard viewer chain changed, need to fix it. } else if (hWndNextViewer != IntPtr.Zero) { Win32.SendMessage(hWndNextViewer, msg, wParam, lParam); //pass the message to the next viewer. } break; case Win32.WmDrawclipboard: Task.Run(async() => { await mainWindow.Dispatcher.InvokeAsync(async() => { Win32.SendMessage(hWndNextViewer, msg, wParam, lParam); //pass the message to the next viewer //clipboard content changed if (Clipboard.ContainsText() && !string.IsNullOrEmpty(Clipboard.GetText().Trim())) { var currentText = Clipboard.GetText().RemoveSpecialCharacters().ToLowerInvariant(); if (!string.IsNullOrEmpty(currentText)) { await Task.Run(async() => { if (cancellationTokenSource.Token.IsCancellationRequested) { return; } await WhenClipboardContainsTextEventHandler.InvokeSafelyAsync(this, new WhenClipboardContainsTextEventArgs { CurrentString = currentText } ); await FlushCopyCommandAsync(); }); } } }, DispatcherPriority.Background); }); break; } return(IntPtr.Zero); }
void TextCaptured(string currentText) { if (this.cancellationTokenSource.Token.IsCancellationRequested) { return; } WhenClipboardContainsTextEventHandler?.Invoke(this, new WhenClipboardContainsTextEventArgs { CurrentString = currentText } ); }
private Task TriggerTextCaptured(string currentText) { return(Task.Run(async() => { if (_cancellationTokenSource.Token.IsCancellationRequested) { return; } await WhenClipboardContainsTextEventHandler.InvokeSafelyAsync(this, new WhenClipboardContainsTextEventArgs { CurrentString = currentText } ); })); }