private void ClipboardChanged(Object sender, SharpClipboard.ClipboardChangedEventArgs e) { if (e != null && e.Content.ToString() != "") { InputText(e.SourceApplication.Title + ": " + e.Content.ToString()); } }
private void ClipboardChanged(Object sender, SharpClipboard.ClipboardChangedEventArgs e) { Debug.WriteLine(e.ContentType.ToString()); // Is the content copied of text type? if (e.ContentType == SharpClipboard.ContentTypes.Text) { var text = (string)e.Content; Debug.WriteLine(text); if (text.IsProductionNumber()) { var newText = WhatsOnMode ? text.ToWhatsOnProductionNumber() : text.ToCleanProductionNumber(); if (newText != text) { ClipboardUtil.TrySetText(newText); } } else if (text.IsEscapedUncPath()) { ClipboardUtil.TrySetText(text.UnescapedUncPath()); } text = Clipboard.GetText(); UpdateHistory(text); } UpdateIcon(); }
/// <summary> /// Изменилось значение буфера обмена Windows /// </summary> /// <param name="sender"></param> /// <param name="e"></param> async void ClipboardMonitor_ClipboardChanged(object sender, SharpClipboard.ClipboardChangedEventArgs e) { if (_keysPasteList.Count == 3 && _keysPasteList[0] == Keys.LControlKey && _keysPasteList[1] == Keys.V) { _globalKeyDown = false; InputSimulator inputSimulator = new InputSimulator(); inputSimulator.Keyboard.KeyDown(VirtualKeyCode.LCONTROL); inputSimulator.Keyboard.KeyPress(VirtualKeyCode.VK_V); inputSimulator.Keyboard.KeyUp(VirtualKeyCode.LCONTROL); _globalKeyDown = true; _keysPasteList.Clear(); return; } if (e.ContentType == SharpClipboard.ContentTypes.Text && (_keysCopyList.Count == 1 || _keysCopyList.Count == 0)) { CopyKeyPress?.Invoke(this, new InputHandlerEventArgs(Keys.Space, (string)e.Content)); } await Task.Run(() => { while (_keysCopyList.Count >= 2 && _keysCopyList[0] == Keys.LControlKey && _keysCopyList[1] == Keys.C) { if (_keysCopyList.Count == 3) { if (e.ContentType == SharpClipboard.ContentTypes.Text) { CopyKeyPress?.Invoke(this, new InputHandlerEventArgs(_keysCopyList[2], (string)e.Content)); } _keysCopyList.Clear(); return; } } }); }
/// <summary> /// Handles the ClipboardChanged event of the ClipboardMonitor control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="SharpClipboard.ClipboardChangedEventArgs"/> instance containing the event data.</param> private void ClipboardMonitor_ClipboardChanged(object sender, SharpClipboard.ClipboardChangedEventArgs e) { if (e.ContentType != SharpClipboard.ContentTypes.Text) { return; } var currentText = e.Content as string; if (string.IsNullOrEmpty(currentText) || this._lastClipboardText == currentText || Keyboard.IsKeyDown(Key.LeftShift)) { return; } var isTradeMessage = false; this._lastClipboardText = currentText; if (TradeEvent.IsTradeMessage(currentText)) { isTradeMessage = true; } else if (TradeEventHelper.IsTradeMessage(currentText)) { isTradeMessage = true; } if (isTradeMessage) { this.NewOffer?.Invoke(this, currentText); } }
private void ClipboardChanged(object sender, SharpClipboard.ClipboardChangedEventArgs e) { if (ClipboardInitialized == false) { ClipboardInitialized = true; return; } if (e.ContentType == SharpClipboard.ContentTypes.Text) { bool alreadyExists = this.Entries.Where((item) => item.Content == clipboard.ClipboardText).Any(); if (clipboard.ClipboardText.Length > 0 && !alreadyExists) { Entry entry = new Entry() { Content = clipboard.ClipboardText }; db.Add(entry); this.Entries.Insert(0, entry); this.uiItems.SelectedIndex = 0; db.SaveChanges(); } } }
private void Clipboard_ClipboardChanged(object sender, SharpClipboard.ClipboardChangedEventArgs e) { if (e.ContentType == SharpClipboard.ContentTypes.Text && e.Content.ToString().Trim() != "") { FrmClipboard f = FrmClipboard.GetForm(e.Content.ToString()); f.Show(); } }
private void sharpClipboard1_ClipboardChanged(object sender, SharpClipboard.ClipboardChangedEventArgs e) { if (e.ContentType == SharpClipboard.ContentTypes.Text) { txtCopiedTexts.Text = sharpClipboard1.ClipboardText; // Alternatively, you can use: // --------------------------- // txtCopiedTexts.Text = (string)e.Content; } else if (e.ContentType == SharpClipboard.ContentTypes.Image) { pbCopiedImage.Image = sharpClipboard1.ClipboardImage; // Alternatively, you can use: // --------------------------- // pbCopiedImage.Image = (Image)e.Content; } else if (e.ContentType == SharpClipboard.ContentTypes.Files) { List <string> files = new List <string>(); foreach (string file in sharpClipboard1.ClipboardFiles) { files.Add(Path.GetFileName(file)); } Debug.WriteLine(sharpClipboard1.ClipboardFiles.ToArray()); lstCopiedFiles.Items.Clear(); lstCopiedFiles.Items.AddRange(files.ToArray()); // Alternatively, you can use: // --------------------------- // lstCopiedFiles.Items.AddRange(((List<string>)e.Content).ToArray())); } else if (e.ContentType == SharpClipboard.ContentTypes.Other) { // Do something with 'e.Content' or alternatively // 'sharpClipboard1.ClipboardObject' property here... // A great example here is when a user has copied an Outlook Mail item. // Such an item will be of a complex object-type format which can be parsed and // examined by using the 'Microsoft.Office.Interop.Outlook' namespace features. // See here: https://stackoverflow.com/questions/25375367/how-to-copy-mailitem-in-outlook-c-sharp // You can however still use the 'ClipboardText' property if you // prefer simply displaying the copied object in text format. txtCopiedTexts.Text = sharpClipboard1.ClipboardText.ToString(); } // Add a TextBox, uncomment the lines below and run. // ------------------------------------------------- // textBox1.Text = $"Name: {e.SourceApplication.Name}, Title: {e.SourceApplication.Title}, " + // $"ID: {e.SourceApplication.ID}, Path: {e.SourceApplication.Path}"; }
private void ClipboardChanged(Object sender, SharpClipboard.ClipboardChangedEventArgs e) { var previousClipboardTimestamp = clipData.Timestamp; readClipboard(); // ignore duplicate clipboard content updates within 100ms if (continuousMode && (clipData.Timestamp - previousClipboardTimestamp).TotalMilliseconds > 100) { updateFilename(); save(); updateSavebutton(); } }
/// <summary> /// 剪贴板内容变化事件处理函数。 /// </summary> private void Clipboard_ClipboardChanged(object sender, SharpClipboard.ClipboardChangedEventArgs e) { // Is the content copied of text type? if (e.ContentType == SharpClipboard.ContentTypes.Text) { // Get the cut/copied text. clipboardWriter.WriteLine(jsonSerializer.Serialize(new { Timestamp = (long)DateTime.Now.Subtract(dt1970) .TotalMilliseconds, content = e.Content.ToString() })); clipboardWriter.Flush(); } }
private void Clipboard_ClipboardChanged(object sender, SharpClipboard.ClipboardChangedEventArgs e) { try { if (e.ContentType == SharpClipboard.ContentTypes.Text && e.Content.ToString().Trim() != "") { //FrmClipboard f = FrmClipboard.GetForm(e.Content.ToString()).Show(); //f.Invoke(new MethodInvoker(delegate () //{ // f.ShowDialog(); //})); } } catch (Exception ex) { } }
private void SharpClipboard_ClipboardChanged(object sender, SharpClipboard.ClipboardChangedEventArgs e) { if (!checkBoxClipboardTextAutoFetch.Checked) { return; } if (checkBoxClipboardTextAutoFetchOnlyWhenActivatingForm.Checked) { return; } if (e.ContentType != SharpClipboard.ContentTypes.Text) { return; } string clipboardText = _sharpClipboard.ClipboardText; OnNewClipboardTextDetected(clipboardText); }
private void ClipboardOnClipboardChanged([CanBeNull] object sender, SharpClipboard.ClipboardChangedEventArgs e) { IClipboardEntry entry = e.ContentType switch { SharpClipboard.ContentTypes.Text => new TextClipboardEntry { Title = _clipboard.ClipboardText.Trim().Replace("\n", "").Replace("\r", ""), Content = _clipboard.ClipboardText }, SharpClipboard.ContentTypes.Image => new ImageClipboardEntry { Title = $"Image - Copied {DateTime.Now.ToShortDateString()}", Content = _clipboard.ClipboardImage }, _ => null }; if (entry != null) { _pluginEngine.PluginByType <ClipboardManagerPlugin>().ClipboardHistory.AddFirst(entry); } }
/// <summary> /// Handles the ClipboardChanged event of the ClipboardMonitor control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="SharpClipboard.ClipboardChangedEventArgs"/> instance containing the event data.</param> /// <exception cref="NotImplementedException"></exception> private void ClipboardMonitor_ClipboardChanged(object sender, SharpClipboard.ClipboardChangedEventArgs e) { if (e.ContentType == SharpClipboard.ContentTypes.Text) { var currentText = e.Content as string; if (string.IsNullOrEmpty(currentText)) { return; } if (this._lastClipboardText == currentText) { return; } this._lastClipboardText = currentText; if (TradeEvent.IsTradeMessage(currentText)) { this.NewOffer?.Invoke(this, currentText); } } }
private void sharpClipboard1_ClipboardChanged(object sender, SharpClipboard.ClipboardChangedEventArgs e) { if (e.ContentType == SharpClipboard.ContentTypes.Text) { txtCopiedTexts.Text = sharpClipboard1.ClipboardText; } else if (e.ContentType == SharpClipboard.ContentTypes.Image) { pbCopiedImage.Image = sharpClipboard1.ClipboardImage; } else if (e.ContentType == SharpClipboard.ContentTypes.Files) { List <string> files = new List <string>(); foreach (string file in sharpClipboard1.ClipboardFiles) { files.Add(Path.GetFileName(file)); } Debug.WriteLine(sharpClipboard1.ClipboardFiles.ToArray()); lstCopiedFiles.Items.Clear(); lstCopiedFiles.Items.AddRange(files.ToArray()); } else if (e.ContentType == SharpClipboard.ContentTypes.Other) { txtCopiedTexts.Text = sharpClipboard1.ClipboardText?.ToString(); } textBox2.Text = $"Name: {e.SourceApplication.Name} \n" + $"Title: {e.SourceApplication.Title} \n" + $"ID: {e.SourceApplication.ID} \n" + $"Handle: {e.SourceApplication.Handle} \n" + $"Path: {e.SourceApplication.Path}"; }
private void ClipboardChanged(Object sender, SharpClipboard.ClipboardChangedEventArgs e) { // Is the content copied of text type? if (e.ContentType == SharpClipboard.ContentTypes.Text) { // Get the cut/copied text. string text = e.Content.ToString(); if (switch1Check == true || switch2Check == true) { for (int counter = 0; counter < text.Length - 1; counter++) { if (switch1Check == true) { if (text[counter + 1].ToString() == "\r") { if (text[counter].ToString() == ".") { continue; } if (text[counter].ToString() == "。") { continue; } text = text.Remove(counter + 1, 2); } } if (switch2Check == true) { if (text[counter].ToString() == " ") { text = text.Remove(counter, 1); } } } } if (switch3Check == true) { if (changeStatus == false) { string appId = Properties.Settings.Default.AppID; string secretKey = Properties.Settings.Default.SecretKey; if (appId == "none" || secretKey == "none") { //MessageBox.Show("请先设置翻译接口", "Copy++"); Show_InputAPIWindow(); } else { text = BaiduTrans(appId, secretKey, text); if (switch4Check == true) { //MessageBox.Show(text); TranslateResult translateResult = new TranslateResult(); translateResult.textBox.Text = text; //translateResult.WindowStartupLocation = WindowStartupLocation.Manual; //translateResult.Left = System.Windows.Forms.Control.MousePosition.X; //translateResult.Top = System.Windows.Forms.Control.MousePosition.Y; translateResult.Show(); //var left = translateResult.Left; //var top = translateResult.Top; } } } } //Prevent loop clipboard.StopMonitoring(); Clipboard.SetText(text); Clipboard.Flush(); InitializeClipboardMonitor(); } // If the cut/copied content is complex, use 'Other'. else if (e.ContentType == SharpClipboard.ContentTypes.Other) { //do nothing // Do something with 'clipboard.ClipboardObject' or 'e.Content' here... } }
//检测到剪切板变化后的操作 private void MyClipboard_ClipboardChanged(object sender, SharpClipboard.ClipboardChangedEventArgs e) { //播放提示音 try { SoundPlayer spPlayer = new SoundPlayer(ClipBoardSet.Default.VoicePath); spPlayer.Play(); spPlayer.Dispose(); } catch (Exception exception) { } if (MyVariable.Variable.SetClip != true) { //实例化数据库操作命令 SQLiteCommand cmdCommand = PublicFunction.SqLiteConnection.CreateCommand(); //取系统时间 DateTime datestart = new DateTime(DateTime.Now.Year, 1, 1, 0, 0, 0); TimeSpan interval = DateTime.Now - datestart; string id, type, time, data, sql, note; //生成ID id = interval.TotalSeconds.ToString().Replace(".", "").Substring(0, 8);//取秒时间差作为索引ID //取现行时间 time = DateTime.Now.ToString(); switch (e.ContentType) { case SharpClipboard.ContentTypes.Text: PublicFunction.Open(PublicFunction.SqLiteConnection); sql = string.Format("SELECT COUNT(*) FROM history WHERE id={0}", id); cmdCommand.CommandText = sql; var reader = cmdCommand.ExecuteScalar(); if (Convert.ToUInt32(reader) != 1) { type = "TEXT"; data = PublicFunction.SqlClean(myClipboard.ClipboardText); note = e.SourceApplication.Title + "\n" + data.Length + "\n" + time; sql = string.Format( "INSERT INTO history (id,type,data,date,lock,note) VALUES ('{0}','{1}','{2}','{3}','{4}','{5}')", id, type, data, time, 0, note); cmdCommand.CommandText = sql; cmdCommand.ExecuteNonQuery(); } break; case SharpClipboard.ContentTypes.Image: PublicFunction.Open(PublicFunction.SqLiteConnection); type = "IMG"; BitmapSource tempImage = Clipboard.GetImage(); string temppath = string.Format(PublicFunction.ImgPath + "{0}.jpg", id); PublicFunction.SaveImageToJpeg(tempImage, 100, temppath); data = temppath; note = e.SourceApplication.Title + "\n" + tempImage.PixelWidth.ToString() + "x" + tempImage.PixelHeight.ToString() + "\n" + time; sql = string.Format("INSERT INTO history (id,type,data,date,lock,note) VALUES ('{0}','{1}','{2}','{3}','{4}','{5}')", id, type, data, time, 0, note); cmdCommand.CommandText = sql; cmdCommand.ExecuteNonQuery(); break; case SharpClipboard.ContentTypes.Files: PublicFunction.Open(PublicFunction.SqLiteConnection); type = "FILE"; data = myClipboard.ClipboardFile; note = e.SourceApplication.Title + "\n" + time; sql = string.Format("INSERT INTO history (id,type,data,date,lock,note) VALUES ('{0}','{1}','{2}','{3}','{4}','{5}')", id, type, data, time, 0, note); cmdCommand.CommandText = sql; cmdCommand.ExecuteNonQuery(); break; } } }
private void ClipboardChanged(Object sender, SharpClipboard.ClipboardChangedEventArgs e) { // Is the content copied of text type? if (e.ContentType == SharpClipboard.ContentTypes.Text) { // Get the cut/copied text. string text = e.Content.ToString(); text = text.Replace("", ""); //Console.WriteLine("123"); if (Switch1Check == true || Switch2Check == true) { for (int counter = 0; counter < text.Length - 1; counter++) { if (Switch1Check == true) { if (text[counter + 1].ToString() == "\r") { if (text[counter].ToString() == ".") { continue; } if (text[counter].ToString() == "。") { continue; } text = text.Remove(counter + 1, 2); //判断英文单词结尾,则加一个空格 if (Regex.IsMatch(text[counter].ToString(), "[a-zA-Z]")) { text = text.Insert(counter + 1, " "); } //判断"-"结尾,则去除"-" if (text[counter].ToString() == "-") { text = text.Remove(counter, 1); } } } if (Switch2Check == true) { if (text[counter].ToString() == " ") { text = text.Remove(counter, 1); } } } } if (Switch3Check == true) { if (ChangeStatus == false) { //判断中文 if (!Regex.IsMatch(text, @"[\u4e00-\u9fa5]")) { string appId = TranslateId; string secretKey = TranslateKey; if (Properties.Settings.Default.AppID != "none" && Properties.Settings.Default.SecretKey != "none") { appId = Properties.Settings.Default.AppID; secretKey = Properties.Settings.Default.SecretKey; } //这个if已经无效 if (appId == "none" || secretKey == "none") { //MessageBox.Show("请先设置翻译接口", "Copy++"); Show_InputAPIWindow(); } else { text = BaiduTrans(appId, secretKey, text); //翻译结果弹窗 if (Switch4Check == true) { //MessageBox.Show(text); TranslateResult translateResult = new TranslateResult(); translateResult.textBox.Text = text; //translateResult.WindowStartupLocation = WindowStartupLocation.Manual; //translateResult.Left = System.Windows.Forms.Control.MousePosition.X; //translateResult.Top = System.Windows.Forms.Control.MousePosition.Y; translateResult.Show(); //var left = translateResult.Left; //var top = translateResult.Top; } } } } } //stop monitoring to prevent loop Clipboard.StopMonitoring(); System.Windows.Clipboard.SetDataObject(text); //System.Windows.Clipboard.Flush(); //restart monitoring InitializeClipboardMonitor(); } // If the cut/copied content is complex, use 'Other'. else if (e.ContentType == SharpClipboard.ContentTypes.Other) { //do nothing // Do something with 'clipboard.ClipboardObject' or 'e.Content' here... } }
private void sharpClipboard1_ClipboardChanged(object sender, SharpClipboard.ClipboardChangedEventArgs e) { if (e.ContentType == SharpClipboard.ContentTypes.Text) { txtCopiedTexts.Text = sharpClipboard1.ClipboardText; // Alternatively, you can use: // --------------------------- // txtCopiedTexts.Text = (string)e.Content; } else if (e.ContentType == SharpClipboard.ContentTypes.Image) { pbCopiedImage.Image = sharpClipboard1.ClipboardImage; // Alternatively, you can use: // --------------------------- // pbCopiedImage.Image = (Image)e.Content; } else if (e.ContentType == SharpClipboard.ContentTypes.Files) { // Declare variable to add the list of copied files. List <string> files = new List <string>(); // Add all copied files to the declared variable. foreach (string file in sharpClipboard1.ClipboardFiles) { files.Add(Path.GetFileName(file)); } Debug.WriteLine(sharpClipboard1.ClipboardFiles.ToArray()); // Add all copied files to the files ListBox. lstCopiedFiles.Items.Clear(); lstCopiedFiles.Items.AddRange(files.ToArray()); // Alternatively, you can use: // --------------------------- // lstCopiedFiles.Items.AddRange(((List<string>)e.Content).ToArray())); } else if (e.ContentType == SharpClipboard.ContentTypes.Other) { // Do something with 'e.Content' or alternatively // 'sharpClipboard1.ClipboardObject' property here... // A great example is when a user has copied an Outlook Mail item. // Such an item will be of a complex object-type that can be parsed and // examined using the 'Microsoft.Office.Interop.Outlook' namespace features. // See here: https://stackoverflow.com/questions/25375367/how-to-copy-mailitem-in-outlook-c-sharp // You can however still use the 'ClipboardText' property if you // prefer simply displaying the copied object in text format. txtCopiedTexts.Text = sharpClipboard1.ClipboardText.ToString(); } // If you wish to get details of the application from where // any text, file, image or other objects were cut/copied, // simply add a TextBox and uncomment the lines below. // -------------------------------------------------------- // textBox1.Text = // $"Name: {e.SourceApplication.Name} \n" + // $"Title: {e.SourceApplication.Title} \n" + // $"ID: {e.SourceApplication.ID} \n" + // $"Handle: {e.SourceApplication.Handle} \n" + // $"Path: {e.SourceApplication.Path}"; // -------------------------------------------------------- // This could come in-handy if you're developing a clipboard-monitoring app. }