private void ClipboardEventHandler(ref System.Windows.Forms.Message m, ref bool handled) { if (handled) { return; } if (m.Msg == WM_DRAWCLIPBOARD) { // notify me ClipboardChanged?.Invoke(this, EventArgs.Empty); // pass on message SendMessage(nextHWnd, m.Msg, m.WParam, m.LParam); handled = true; } else if (m.Msg == WM_CHANGECBCHAIN) { if (m.WParam == nextHWnd) { nextHWnd = m.LParam; } else { SendMessage(nextHWnd, m.Msg, m.WParam, m.LParam); } } }
static Clipboard() { App.Current.MainWindow.Loaded += (sender, e) => { try { _monitor = new Monitor(App.Current.MainWindow); _monitor.ClipboardChanged += Listener; } catch (Exception ex) { Log.Error(ex); } }; App.Current.Exit += (sender, e) => { try { _monitor.ClipboardChanged -= Listener; _monitor.Dispose(); _monitor = null; } catch (Exception ex) { Log.Error(ex); } }; void Listener(object sender, EventArgs e) { ClipboardChanged?.Invoke(sender, e); } }
/// <summary> /// Clears the contents of the clipboard /// </summary> public void Clear() { _currentData.Clear(); _currentData = null; ClipboardChanged?.Invoke(this, new ClipboardEventArgs(null, ClipboardEventType.Clear)); }
private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { // do stuff switch (msg) { // // The WM_DRAWCLIPBOARD message is sent to the first window // in the clipboard viewer chain when the content of the // clipboard changes. This enables a clipboard viewer // window to display the new content of the clipboard. // case (int)NativeConsts.Message.WM_DRAWCLIPBOARD: // // Each window that receives the WM_DRAWCLIPBOARD message // must call the SendMessage function to pass the message // on to the next window in the clipboard viewer chain. // NativeMethods.SendMessage(nextViewer, msg, wParam, lParam); ClipboardChanged?.Invoke(this, new EventArgs()); handled = true; break; // // The WM_CHANGECBCHAIN message is sent to the first window // in the clipboard viewer chain when a window is being // removed from the chain. // case (int)NativeConsts.Message.WM_CHANGECBCHAIN: // When a clipboard viewer window receives the WM_CHANGECBCHAIN message, // it should call the SendMessage function to pass the message to the // next window in the chain, unless the next window is the window // being removed. In this case, the clipboard viewer should save // the handle specified by the lParam parameter as the next window in the chain. // // wParam is the Handle to the window being removed from // the clipboard viewer chain // lParam is the Handle to the next window in the chain // following the window being removed. if (wParam == nextViewer) { // // If wParam is the next clipboard viewer then it // is being removed so update pointer to the next // window in the clipboard chain // nextViewer = lParam; } else { NativeMethods.SendMessage(nextViewer, msg, wParam, lParam); } handled = true; break; } return(IntPtr.Zero); }
public ClipboardMonitor() { _messageListener = new MessageListener(() => { var contents = ClipboardEx.GetContents(); ClipboardChanged?.Invoke(this, new ClipboardChangedEventArgs(contents)); }); }
private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "SharedClipboard") { Log.d(TAG, "Clipboard mode changed"); ClipboardChanged?.Invoke(this, new ClipboardChangedEventArgs(true)); } }
private void OnClipboardChanged() { var dataObject = Clipboard.GetDataObject(); if (dataObject != null) { ClipboardChanged?.Invoke(this, new ClipboardChangedEventArgs(dataObject)); } }
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == NativeMethods.WM_CLIPBOARDUPDATE) { ClipboardChanged?.Invoke(this, EventArgs.Empty); } return(IntPtr.Zero); }
public static void SetClipboard(string message) { // general GUIUtility.systemCopyBuffer = message; //event ClipboardChanged?.Invoke(); //analytics SGAnalytics.AnalyticsTraking("SetClipboard", "message", message); }
static Clipboard() { ClipboardMonitor c = new ClipboardMonitor(); c.ClipboardUpdate += (p1, p2) => { currentData = global::System.Windows.Clipboard.GetDataObject(); ClipboardChanged?.Invoke(p1, new ClipboardEventArgs(currentData)); }; }
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == NativeMethods.ClipboardUpdate) { ClipboardChanged?.Invoke(this, EventArgs.Empty); handled = true; } return(WndProcSuccess); }
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == NativeMethods.WM_CLIPBOARDUPDATE) { _mainWindow.RunWhenever(() => { ClipboardChanged?.Invoke(null, EventArgs.Empty); }); handled = true; } return(WndProcSuccess); }
private void OnClipboardChangeTimer(Object source, EventArgs e) { if (Clipboard.ContainsText()) { String curText; try { curText = Clipboard.GetText(); } catch (Exception err) { Log.e(TAG, "Error while opening clipboard: " + err.Message); return; } if (IsSharedLocal && m_strLastClipboardText != null && !curText.Equals(m_strLastClipboardText, StringComparison.Ordinal)) { String curTextHtml = null; if (Clipboard.ContainsText(TextDataFormat.Html)) { // Android wants the pure html text, peel away everything else (see above for the header) String strClipHtml = Clipboard.GetText(TextDataFormat.Html); int nStartFragmentDesc = strClipHtml.ToLower().IndexOf("startfragment:") + "startfragment:".Length; int nEndFragmentDesc = strClipHtml.ToLower().IndexOf("endfragment:") + "endfragment:".Length; if (nStartFragmentDesc > 0 && nStartFragmentDesc < strClipHtml.Length && nEndFragmentDesc > 0 && nEndFragmentDesc < strClipHtml.Length) { int nStartFragmentIdx; int nEndFragmentIdx; if (int.TryParse(new string(strClipHtml.Substring(nStartFragmentDesc).Trim().TakeWhile(c => char.IsDigit(c)).ToArray()), out nStartFragmentIdx) && int.TryParse(new string(strClipHtml.Substring(nEndFragmentDesc).Trim().TakeWhile(c => char.IsDigit(c)).ToArray()), out nEndFragmentIdx)) { if (nStartFragmentIdx < nEndFragmentIdx && nEndFragmentIdx <= Encoding.UTF8.GetByteCount(strClipHtml)) { // Positions are ByteCount rather than CharCount try { curTextHtml = System.Text.Encoding.UTF8.GetString(System.Text.Encoding.UTF8.GetBytes(strClipHtml), nStartFragmentIdx, nEndFragmentIdx - nStartFragmentIdx); } catch (Exception err) when(err is ArgumentException || err is DecoderFallbackException) { Log.e(TAG, "Error re-decoding string"); } } } } } Log.d(TAG, "Local Clipboard changed, propagating content, contains html: " + !String.IsNullOrEmpty(curTextHtml)); ClipboardChanged?.Invoke(this, new ClipboardChangedEventArgs(curText, curTextHtml)); } m_strLastClipboardText = curText; } else { m_strLastClipboardText = null; } }
/// <summary> /// Stores the given object on this clipboard. /// Setting a new object clears any object that was already on the clipboard /// </summary> /// <param name="dataObject">The new object to set to the clipboard</param> public void SetObject(IClipboardObject dataObject) { if (_currentData != null && _currentData != dataObject) { _currentData.Clear(); } _currentData = dataObject; ClipboardChanged?.Invoke(this, new ClipboardEventArgs(_currentData, ClipboardEventType.Set)); }
/// <summary> /// Called from WndProc, fires event handler call to ClipboardChangedEventArgs. On Error, displays popup of error /// </summary> void OnClipboardChanged() { try { IDataObject iData = System.Windows.Forms.Clipboard.GetDataObject(); ClipboardChanged?.Invoke(this, new ClipboardChangedEventArgs(iData)); } catch (Exception e) { MessageBox.Show(e.ToString()); } }
private void OnClipboardChanged() { try { IDataObject iData = Clipboard.GetDataObject(); ClipboardChanged?.Invoke(this, new ClipboardChangedEventArgs(iData)); } catch (Exception e) { Trace.Write(e.ToString()); } }
private void OnClipboardChanged() { try { IDataObject dataObject = Clipboard.GetDataObject(); if (dataObject != null) { ClipboardChanged?.Invoke(this, new ClipboardChangedEventArgs(dataObject)); } } catch (ExternalException) { } }
/// <summary>Call when content of clipboard is changed</summary> private void OnClipboardChanged() { try { IDataObject iData = Clipboard.GetDataObject(); ClipboardChanged?.Invoke(this, new Tuple <IDataObject>(iData)); } //catch (Exception e) catch (Exception) { // Swallow or pop-up, not sure // Trace.Write(e.ToString()); //MessageBox.Show(e.ToString()); } }
protected void RaiseClipboardChanged(string newData) { if (newData == "") { return; } if (previous == newData) { return; } previous = newData; ClipboardChanged?.Invoke(this, newData); }
void OnClipboardChanged() { try { IDataObject iData = Clipboard.GetDataObject(); ClipboardChanged?.Invoke(this, new ClipboardChangedEventArgs(iData)); } catch (Exception e) { // Swallow or pop-up, not sure // Trace.Write(e.ToString()); MessageBox.Show(e.ToString()); } }
protected virtual void OnClipboardChanged() { try { IDataObject iData = Clipboard.GetDataObject(); var e = new ClipboardChangedEventArgs(iData); ClipboardChanged?.Invoke(this, e); if (e.Changed != null) { Clipboard.SetText(e.Changed); } } catch (Exception e) { Debug.WriteLine(e); } }
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == NativeMethods.WM_CLIPBOARDUPDATE) { try { var text = Clipboard.GetText(); ClipboardChanged?.Invoke(this, text); } catch (COMException) { // trying to silence "data in clipboard is invalid" exception // we simply won't update our clipboard in that case } } return(IntPtr.Zero); }
static Clipboard() { App.Current.Activated += (sender, e) => { _monitor = new Monitor(App.Current.MainWindow); _monitor.ClipboardChanged += Listener; }; App.Current.Exit += (sender, e) => { _monitor.ClipboardChanged -= Listener; _monitor.Dispose(); _monitor = null; }; void Listener(object sender, EventArgs e) { ClipboardChanged?.Invoke(sender, e); } }
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { switch (msg) { case WM_DRAWCLIPBOARD: ClipboardChanged?.Invoke(); SendMessage(nextClipboardViewer, msg, wParam, lParam); break; case WM_CHANGECBCHAIN: if (wParam == nextClipboardViewer) { nextClipboardViewer = lParam; } else { SendMessage(nextClipboardViewer, msg, wParam, lParam); } break; } return(IntPtr.Zero); }
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { switch (msg) { case NativeMethods.WM_CLIPBOARDUPDATE: try { // Try to get clipboard content parsed as a string string content = GetClipboardContent(); // Ignore invalid clipboard content if (string.IsNullOrEmpty(content)) { break; } // Ignore the content that was put back into the clipboard if (content == lastSetContent) { break; } // Notify about new clip ClipboardChanged?.Invoke( sender: this, e: new ClipboardEventArgs( source: WindowHelper.GetActiveProcessName(), payload: content ) ); } catch (Exception ex) { Logger.Error("Unable to read clipboard content during WM_CLIPBOARDUPDATE event!", ex); } break; } return(IntPtr.Zero); }
/// <summary> /// An application-defined function that processes messages sent to a window. The WNDPROC type defines a pointer to this callback function. /// </summary> /// <param name="hwnd">A handle to the window.</param> /// <param name="msg">The message.</param> /// <param name="wParam">Additional message information. The contents of this parameter depend on the value of the <param name="msg"/> parameter.</param> /// <param name="lParam">Additional message information. The contents of this parameter depend on the value of the <param name="msg"/> parameter.</param> /// <param name="handled"></param> /// <returns>The return value is the result of the message processing and depends on the message sent.</returns> private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg != Consts.ClipboardUpdateMessage) { return(IntPtr.Zero); } try { var data = System.Windows.Clipboard.GetDataObject() as DataObject; var isCut = false; if (data == null) { return(IntPtr.Zero); } if (data.GetDataPresent(Consts.DropEffectFormatName)) { var preferredDropEffect = data.GetData(Consts.DropEffectFormatName) as System.IO.MemoryStream; if (preferredDropEffect != null) { isCut = preferredDropEffect.ToArray().SequenceEqual(new byte[] { 2, 0, 0, 0 }); } } Logger.Instance.Information("New data detected into the Windows clipboard."); ClipboardChanged?.Invoke(this, new ClipboardHookEventArgs(data, isCut, DateTime.Now.Ticks)); } catch (Exception ex) { Logger.Instance.Warning($"A data has been copied by the user, but the app is not able to retrieve it."); Logger.Instance.Error(ex); } return(IntPtr.Zero); }
private void OnClipboardChanged() { ClipboardChanged?.Invoke(this, EventArgs.Empty); }
void OnClipboardChanged() { ClipboardChanged?.Invoke(this, new EventArgs()); }
/// <summary> /// Invokes the <see cref="ClipboardChanged"/> event with formal parameters. /// </summary> /// <param name="content">The current clipboard content.</param> /// <param name="type">The current clipboard content-type.</param> internal void Invoke(object content, ContentTypes type, SourceApplication source) { ClipboardChanged?.Invoke(this, new ClipboardChangedEventArgs(content, type, source)); }
static void _notifyClipboardChanged() { ClipboardChanged?.Invoke(); }