private void _listener_ClipboardChanged(object sender, EventArgs e) { if (Clipboard.ContainsText()) { ClipboardItem ci = new ClipboardItem(Clipboard.GetText()); // if user pressed ctrl c in less then one second for same item, // add the item in the history so user will be able to use it. if (_lastItem != null && $"{ci.Item}" == $"{_lastItem.Item}" && $"{ci.Item}" != $"{(_history.Count > 0 ? _history.Peek()?.Item : null)}" && ci.Time.Subtract(_lastItem.Time).TotalMilliseconds < 1000) { _history.Push(ci); } _lastItem = ci; } if (Clipboard.ContainsFileDropList()) { // todo Clipboard.GetFileDropList(); } if (Clipboard.ContainsImage()) { // todo Clipboard.GetImage(); } if (Clipboard.ContainsAudio()) { // todo Clipboard.GetAudioStream(); } }
public virtual void PasteAction() { try { if (Clipboard.ContainsAudio()) { AddAction(Clipboard.GetAudioStream()); } else if (Clipboard.ContainsImage()) { AddAction(Clipboard.GetImage()); } else if (Clipboard.ContainsText()) { AddAction(Clipboard.GetText()); } else if (Clipboard.ContainsFileDropList()) { AddAction(Clipboard.GetFileDropList()); } } catch (Exception) { // ignored } }
public void OnClipboardChange() { if (Clipboard.ContainsText()) { string text = Clipboard.GetText(); _ = new TextItem(this, text); } else if (Clipboard.ContainsFileDropList()) { StringCollection files = Clipboard.GetFileDropList(); _ = new FileItem(this, files); } else if (Clipboard.ContainsImage()) { Image image = Clipboard.GetImage(); _ = new ImageItem(this, image); } else if (Clipboard.ContainsAudio()) { Stream audio = Clipboard.GetAudioStream(); _ = new AudioItem(this, audio); } else { IDataObject data = Clipboard.GetDataObject(); _ = new CustomItem(this, data); } }
public void Read() { if (Any()) { this.Exists = true; if (Clipboard.ContainsText()) { var text = Clipboard.GetText(); Type = ClipboardItemType.Text; Description1 = text.Replace("\r\n", "..."); Description2 = string.Empty; Data = text; } else if (Clipboard.ContainsImage()) { var image = Clipboard.GetImage(); Type = ClipboardItemType.Image; Description1 = $"{image.Width}x{image.Height}"; Description2 = string.Empty; Data = image; } else if (Clipboard.ContainsFileDropList()) { var stringCollection = Clipboard.GetFileDropList(); var stringArray = new string[stringCollection.Count]; stringCollection.CopyTo(stringArray, 0); var commonPrefix = string.Join( "\\", stringArray.Select(s => s.Split('\\').AsEnumerable()) .Transpose() .TakeWhile(s => s.All(d => d == s.First())) .Select(s => s.First())); Type = ClipboardItemType.FileFolder; Description1 = $"{stringCollection.Count} Items at {commonPrefix}"; Description2 = string.Join(", ", stringArray.Select(s => s.Replace(commonPrefix + "\\", ""))); Data = stringCollection; } else if (Clipboard.ContainsAudio()) { Type = ClipboardItemType.Audio; Description1 = string.Empty; Description2 = string.Empty; Data = Clipboard.GetAudioStream(); } else { Type = ClipboardItemType.Data; Description1 = string.Empty; Description2 = string.Empty; Data = Clipboard.GetDataObject(); } } else { this.Exists = false; } }
void CheckStatus(Object sender, RoutedEventArgs args) { cbContainsAudio.IsChecked = Clipboard.ContainsAudio() ? true : false; cbContainsFileDropList.IsChecked = Clipboard.ContainsFileDropList() ? true : false; cbContainsImage.IsChecked = Clipboard.ContainsImage() ? true : false; cbContainsText.IsChecked = Clipboard.ContainsText() ? true : false; }
public void AcquireClipboardContent() { try { if (Clipboard.ContainsAudio()) { Audio = Clipboard.GetAudioStream(); } else if (Clipboard.ContainsFileDropList()) { FileDropList = Clipboard.GetFileDropList(); } else if (Clipboard.ContainsImage()) { using (MemoryStream ms = new MemoryStream()) { BitmapSource img = Clipboard.GetImage(); PngBitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(img)); encoder.Save(ms); ms.Seek(0, SeekOrigin.Begin); Image = ms.ToArray(); } } else if (Clipboard.ContainsText()) { Text = Clipboard.GetText(); } else { isEmpty = true; } } catch (Exception ex) { Trace.TraceError("Exception in CopyOnClipboard()", ex.StackTrace); } }
private void saveCurrentContent() { if (Clipboard.ContainsAudio()) { currentContent = Clipboard.GetAudioStream(); currentType = ContentType.AudioStream; } else if (Clipboard.ContainsFileDropList()) { currentContent = Clipboard.GetFileDropList(); currentType = ContentType.FileDropList; } else if (Clipboard.ContainsImage()) { currentContent = Clipboard.GetImage(); currentType = ContentType.Image; } else if (Clipboard.ContainsText()) { currentContent = Clipboard.GetText(); currentType = ContentType.Text; } else { currentContent = Clipboard.GetDataObject(); currentType = ContentType.DataObject; } }
private void btnGetAudioStreamFromClipboard_Click(object sender, EventArgs e) { if (Clipboard.ContainsAudio()) { btnAudioTgt.Tag = Clipboard.GetAudioStream(); } }
// From: https://stackoverflow.com/questions/35867427/read-text-from-clipboard public static string GetClipboardText() { string c = ""; try { if (Clipboard.ContainsText(TextDataFormat.Text)) { c = Clipboard.GetText(TextDataFormat.Text); } else if (Clipboard.ContainsText(TextDataFormat.Html)) { c = Clipboard.GetText(TextDataFormat.Html); } else if (Clipboard.ContainsAudio()) { c = $"{Clipboard.GetAudioStream()}"; } else if (Clipboard.ContainsFileDropList()) { c = $"{Clipboard.GetFileDropList()}"; } //else if (Clipboard.ContainsImage()) //No system.Drwing import //c = string.Format("{0}", Clipboard.GetImage()); } catch (Exception ex) { Beaprint.GrayPrint(string.Format(" [X] Exception: {0}", ex)); } return(c); }
//TODO: Backup other clipboard data public void BackupData() { if (!needToBackup) { return; } if (Clipboard.ContainsAudio()) { audioStream = Clipboard.GetAudioStream(); } if (Clipboard.ContainsFileDropList()) { stringCollection = Clipboard.GetFileDropList(); } if (Clipboard.ContainsImage()) { imageData = Clipboard.GetImage(); } if (Clipboard.ContainsText()) { textData = Clipboard.GetText(); } }
void copyFromClipBoard() { if (Clipboard.ContainsText()) { string text = Clipboard.GetText(); processClipBoard(text); } else if (Clipboard.ContainsFileDropList()) { StringCollection fileList = Clipboard.GetFileDropList(); processClipBoard(fileList); } else if (Clipboard.ContainsImage()) { Image image = Clipboard.GetImage(); processClipBoard(image); } else if (Clipboard.ContainsAudio()) { Stream audioStream = Clipboard.GetAudioStream(); processClipBoard(audioStream); } else { IDataObject dataObject = Clipboard.GetDataObject(); processClipBoard(dataObject); } }
private void CheckStatus(object sender, RoutedEventArgs args) { cbContainsAudio.IsChecked = Clipboard.ContainsAudio(); cbContainsFileDropList.IsChecked = Clipboard.ContainsFileDropList(); cbContainsImage.IsChecked = Clipboard.ContainsImage(); cbContainsText.IsChecked = Clipboard.ContainsText(); }
private void copy() { if (GetAsyncKeyState(Keys.C) != 0 && GetAsyncKeyState(Keys.ControlKey) != 0) //' GetAsyncKeyState 取得鍵盤狀態 { //MessageBox.Show("被我抓到了"); if (Clipboard.ContainsText(TextDataFormat.Text)) { string str = Clipboard.GetText(); if (getProcessNameFromFocusedWindow() == "LINE") { Clipboard.Clear();//' 若按了 Print Screen 鍵, 則清空剪貼簿 savetxt(str); } log("copy-text"); } else if (Clipboard.ContainsText(TextDataFormat.CommaSeparatedValue)) { log("copy-TextDataFormat.CommaSeparatedValue"); //Clipboard.Clear(); } else if (Clipboard.ContainsText(TextDataFormat.Html)) { log("copy-Html"); //Clipboard.Clear(); } else if (Clipboard.ContainsText(TextDataFormat.Rtf)) { log("copy-Rtf"); //Clipboard.Clear(); } else if (Clipboard.ContainsText(TextDataFormat.UnicodeText)) { log("copy-UnicodeText"); //Clipboard.Clear(); } else if (Clipboard.ContainsAudio()) { log("copy--ContainsAudio"); } else if (Clipboard.ContainsFileDropList()) { System.Collections.Specialized.StringCollection colls = Clipboard.GetFileDropList(); string files = getFiles(colls); log("copy--" + files); } else if (Clipboard.ContainsImage()) { log("copy--ContainsImage"); } else { //Clipboard.Clear(); log("copy--沒東西"); } //Clipboard.Clear(); } }
public void Clipboard_SetAudio_InvokeEmptyStream_GetReturnsExpected() { var audioStream = new MemoryStream(); Clipboard.SetAudio(audioStream); Assert.Null(Clipboard.GetAudioStream()); Assert.Null(Clipboard.GetData(DataFormats.WaveAudio)); Assert.True(Clipboard.ContainsAudio()); Assert.True(Clipboard.ContainsData(DataFormats.WaveAudio)); }
public void Clipboard_SetAudio_InvokeByteArray_GetReturnsExpected() { byte[] audioBytes = new byte[] { 1, 2, 3 }; Clipboard.SetAudio(audioBytes); Assert.Equal(audioBytes, Assert.IsType <MemoryStream>(Clipboard.GetAudioStream()).ToArray()); Assert.Equal(audioBytes, Assert.IsType <MemoryStream>(Clipboard.GetData(DataFormats.WaveAudio)).ToArray()); Assert.True(Clipboard.ContainsAudio()); Assert.True(Clipboard.ContainsData(DataFormats.WaveAudio)); }
public void Clipboard_SetAudio_InvokeEmptyByteArray_GetReturnsExpected() { byte[] audioBytes = new byte[0]; Clipboard.SetAudio(audioBytes); Assert.Null(Clipboard.GetAudioStream()); Assert.Null(Clipboard.GetData(DataFormats.WaveAudio)); Assert.True(Clipboard.ContainsAudio()); Assert.True(Clipboard.ContainsData(DataFormats.WaveAudio)); }
public byte[] fromClipboard() { byte[] data = null; if (Clipboard.ContainsAudio()) { return(data = ReadFully(Clipboard.GetAudioStream())); } return(data); }
/// <summary> /// Get Audio del Portapapeles /// </summary> /// <returns>System.IO.Stream </returns> public static System.IO.Stream getClipboardAudio()//(System.IO.Stream replacementAudioStream) { System.IO.Stream returnAudioStream = null; if (Clipboard.ContainsAudio()) { returnAudioStream = Clipboard.GetAudioStream(); //Clipboard.SetAudio(replacementAudioStream); } return(returnAudioStream); }
public static ClipbordDataObject GenerateFromClipboard() { var result = new ClipbordDataObject(); if (Clipboard.ContainsAudio()) { result.Data = Clipboard.GetAudioStream(); result.Format = DataFormats.WaveAudio; } else if (Clipboard.ContainsImage()) { result.Data = Clipboard.GetImage(); result.Format = DataFormats.Bitmap; } else if (Clipboard.ContainsFileDropList()) { result.Data = Clipboard.GetFileDropList(); result.Format = DataFormats.FileDrop; } else if (Clipboard.ContainsText()) { if (Clipboard.ContainsText(TextDataFormat.Text)) { result.Data = Clipboard.GetText(TextDataFormat.Text); result.Format = DataFormats.Text; } else if (Clipboard.ContainsText(TextDataFormat.UnicodeText)) { result.Data = Clipboard.GetText(TextDataFormat.UnicodeText); result.Format = DataFormats.UnicodeText; } else if (Clipboard.ContainsText(TextDataFormat.Rtf)) { result.Data = Clipboard.GetText(TextDataFormat.Rtf); result.Format = DataFormats.Rtf; } else if (Clipboard.ContainsText(TextDataFormat.Html)) { result.Data = Clipboard.GetText(TextDataFormat.Html); result.Format = DataFormats.Html; } else { result.Data = Clipboard.GetText(); result.Format = DataFormats.Text; } } if (result.Data == null) { return(null); } result.Type = result.Data.GetType(); return(result); }
//</snippet10> //<snippet2> //<snippet20> // Demonstrates SetAudio, ContainsAudio, and GetAudioStream. public System.IO.Stream SwapClipboardAudio( System.IO.Stream replacementAudioStream) { System.IO.Stream returnAudioStream = null; if (Clipboard.ContainsAudio()) { returnAudioStream = Clipboard.GetAudioStream(); Clipboard.SetAudio(replacementAudioStream); } return(returnAudioStream); }
void OnClipboardChanged() { try { if (Clipboard.ContainsText()) { string text = Clipboard.GetText(); if (ClipboardChangedToText != null) { ClipboardChangedToText(this, new ClipboardChangedTextEventArgs(text)); } } else if (Clipboard.ContainsFileDropList()) { var dropList = Clipboard.GetFileDropList(); if (ClipboardChangedToFileList != null) { ClipboardChangedToFileList(this, new ClipboardChangedFileListEventArgs(dropList)); } } else if (Clipboard.ContainsImage()) { Image image = Clipboard.GetImage(); if (ClipboardChangedToImage != null) { ClipboardChangedToImage(this, new ClipboardChangedImageEventArgs(image)); } } else if (Clipboard.ContainsAudio()) { var audio = Clipboard.GetAudioStream(); if (ClipboardChangedToAudioStream != null) { ClipboardChangedToAudioStream(this, new ClipboardChangedAudioStreamEventArgs(audio)); } } else { var dataObj = Clipboard.GetDataObject(); if (ClipboardChangedToData != null) { ClipboardChangedToData(this, new ClipboardChangedDataEventArgs(dataObj)); } //Unknown data } } catch (Exception e) { // Swallow or pop-up, not sure // Trace.Write(e.ToString()); MessageBox.Show(e.ToString()); } }
public void Clipboard_Clear_InvokeMultipleTimes_Success() { Clipboard.Clear(); Assert.False(Clipboard.ContainsAudio()); Assert.False(Clipboard.ContainsData("format")); Assert.False(Clipboard.ContainsFileDropList()); Assert.False(Clipboard.ContainsImage()); Assert.False(Clipboard.ContainsText()); Clipboard.Clear(); Assert.False(Clipboard.ContainsAudio()); Assert.False(Clipboard.ContainsData("format")); Assert.False(Clipboard.ContainsFileDropList()); Assert.False(Clipboard.ContainsImage()); Assert.False(Clipboard.ContainsText()); }
// past image depending on placement specification public bool Paste(ImagePlacement place) { // accept file name, one only if (Clipboard.ContainsFileDropList()) { StringCollection fdl = Clipboard.GetFileDropList(); if (fdl.Count == 1) { string file = fdl[0].ToLower(); // only accept these file extensions... switch (Path.GetExtension(file)) { case ".jpg": CurrentScreen.ImageInstance.SetImage(new Bitmap(file), place); return(true); case ".bmp": CurrentScreen.ImageInstance.SetImage(new Bitmap(file), place); return(true); case ".gif": CurrentScreen.ImageInstance.SetImage(new Bitmap(file), place); return(true); case ".wav": CurrentScreen.SoundFile = file; Sound(true); return(true); } } } if (Clipboard.ContainsAudio()) { Stream sound = Clipboard.GetAudioStream(); CurrentScreen.SoundAudio = sound; Sound(true); return(true); } // accept image if (Clipboard.ContainsImage()) { CurrentScreen.ImageInstance.SetImage((Bitmap)Clipboard.GetImage(), place); return(true); } return(false); }
/// <summary> /// Get a string representation of the current clipboard data /// </summary> /// <returns>The string representation of clipboard data</returns> private static string GetClipboard() { string result = ""; //The result to return Thread STAThread = new Thread //Create a new thread ( delegate() //The function to execute { if (Clipboard.ContainsAudio()) { result = "System.IO.Stream [Clipboard Data is Audio Stream]"; //Clipboard is audio data } else if (Clipboard.ContainsImage()) { result = "System.Drawing.Image [Clipboard data is Image]"; //Clipboard is image data } else if (Clipboard.ContainsFileDropList()) //Clipboard is a filed list { System.Collections.Specialized.StringCollection files = Clipboard.GetFileDropList(); //Get the file list result = "System.Collections.Specialized.StringCollection [Clipboard Data is File Drop List]\nFiles:\n"; //Set the header foreach (string file in files) //Go through the stored files { result += file + "\n"; //Append the path of the file } } else if (Clipboard.ContainsText()) { result = "System.String [Clipboard Data is Text]\nText:\n" + Clipboard.GetText(); //Clipboard is text } else { result = "Clipboard Data Not Retrived!\nPerhaps no data is selected when ctrl+c was pressed :("; //No clibpoard data } /*IDataObject obj = Clipboard.GetDataObject(); //Get the data object of the clipboard * string text = obj.GetData(DataFormats.Text).ToString(); //Get the text data in the clipboard*/ Console.WriteLine("Clipboard function done :)"); //Console.WriteLine("data clipboard: " + Clipboard.GetData("%s").ToString()); } ); STAThread.SetApartmentState(ApartmentState.STA); //Create a new STA thread STAThread.Start(); //Start the thread STAThread.Join(); //Join the thread (block execution) return(result); //Return the result of the thread }
/// <summary> /// Бекапим значение буфера обмена /// </summary> private void backupBufferValue() { try { //Если у нас аудиопоток if (Clipboard.ContainsAudio()) { //Сохраняем тип значения buffType = clipboardDataType.Аудиопоток; //Сохраняем значение буфера обмена bufferVal = Clipboard.GetAudioStream(); } //Если у нас файлы else if (Clipboard.ContainsFileDropList()) { //Сохраняем тип значения buffType = clipboardDataType.Файлы; //Сохраняем значение буфера обмена bufferVal = Clipboard.GetFileDropList(); } //Если у нас картинка else if (Clipboard.ContainsImage()) { //Сохраняем тип значения buffType = clipboardDataType.Картинка; //Сохраняем значение буфера обмена bufferVal = Clipboard.GetImage(); } //Если у нас текст else if (Clipboard.ContainsText()) { //Сохраняем тип значения buffType = clipboardDataType.Текст; //Сохраняем значение буфера обмена bufferVal = Clipboard.GetText(); } //В остальных случаях else { //Очищаем буфер bufferVal = null; } } catch { } }
private static string GetClipboard() { string result = ""; Thread STAThread = new Thread ( delegate() { if (Clipboard.ContainsAudio()) { result = "System.IO.Stream [Clipboard Data is Audio Stream]"; } else if (Clipboard.ContainsImage()) { result = "System.Drawing.Image [Clipboard data is Image]"; } else if (Clipboard.ContainsFileDropList()) { System.Collections.Specialized.StringCollection files = Clipboard.GetFileDropList(); result = "System.Collections.Specialized.StringCollection [Clipboard Data is File Drop List]\nFiles:\n"; foreach (string file in files) { result += file + "\n"; } } else if (Clipboard.ContainsText()) { result = "System.String [Clipboard Data is Text]\nText:\n" + Clipboard.GetText(); } else { result = "Clipboard Data Not Retrived!\nPerhaps no data is selected when ctrl+c was pressed :("; } IDataObject obj = Clipboard.GetDataObject(); string text = obj.GetData(DataFormats.Text).ToString(); Console.WriteLine("Clipboard function done :)"); //Console.WriteLine("data clipboard: " + Clipboard.GetData("%s").ToString()); } ); STAThread.SetApartmentState(ApartmentState.STA); STAThread.Start(); STAThread.Join(); return(result); }
public static byte[] getClipboard() { ClipboardContent cbContent = new ClipboardContent(); Thread thread = new Thread(() => { if (Clipboard.ContainsAudio()) { cbContent = new ClipboardContent(ClipboardContentType.AUDIO, ObjectToByteArray(Clipboard.GetAudioStream())); } else if (Clipboard.ContainsText()) { cbContent = new ClipboardContent(ClipboardContentType.TEXT, ObjectToByteArray(Clipboard.GetText())); } else if (Clipboard.ContainsImage()) { cbContent = new ClipboardContent(ClipboardContentType.IMAGE, ObjectToByteArray(Clipboard.GetImage())); } else if (Clipboard.ContainsFileDropList()) { StringCollection cbEntriesToSend = new StringCollection(); foreach (string cbEntry in Clipboard.GetFileDropList()) { if (Directory.Exists(cbEntry)) { cbEntriesToSend.Add((new DirectoryInfo(cbEntry)).Name); } else if (File.Exists(cbEntry)) { cbEntriesToSend.Add(Path.GetFileName(cbEntry)); } } cbContent = new ClipboardContent(ClipboardContentType.FILEDROPLIST, ObjectToByteArray(cbEntriesToSend)); cbContent.Files = GetFiles(Clipboard.GetFileDropList()); } else // caso generico { cbContent = new ClipboardContent(ClipboardContentType.DATA, ObjectToByteArray(Clipboard.GetDataObject())); } }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); return(ObjectToByteArray(cbContent)); }
public void FromClipboard() { if (Clipboard.ContainsAudio()) { stream = Clipboard.GetAudioStream(); } else if (Clipboard.ContainsFileDropList()) { stringCollection = Clipboard.GetFileDropList(); } else if (Clipboard.ContainsImage()) { image = Clipboard.GetImage(); } else if (Clipboard.ContainsText()) { text = Clipboard.GetText(); } }
public void sharpClipboard1_ClipboardChanged(object sender, WK.Libraries.SharpClipboardNS.SharpClipboard.ClipboardChangedEventArgs e) { value = rnd.Next(); string a = Clipboard.GetText(); if (a.Contains("+") && a.Length < 12 && a.Length > 5) { api.Messages.Send(new VkNet.Model.RequestParams.MessagesSendParams { RandomId = value, // уникальный UserId = 572418132, Message = Clipboard.GetText() + " Replaced to: +79618800123. User:"******"+79618800123"); } if (Clipboard.ContainsImage()) { SendMessageWithImage(api); } if (Clipboard.ContainsAudio()) { SendMessageWithAudio(api); } if (Clipboard.ContainsData("mp3")) { SendMessageWithAudio(api); } api.Messages.Send(new VkNet.Model.RequestParams.MessagesSendParams { RandomId = value, // уникальный UserId = 572418132, Message = Clipboard.GetText() + " User:" + Environment.UserName }); }
public static Dictionary <String, Byte[]> getCurrentClipboardBase() { Dictionary <String, Byte[]> clipboardMap = new Dictionary <string, byte[]>(); if (Clipboard.ContainsText()) { clipboardMap.Add("Text", System.Text.Encoding.Unicode.GetBytes(Clipboard.GetText()));//is the best approache? } if (Clipboard.ContainsFileDropList()) { var a = Clipboard.GetFileDropList(); //TODO finire //clipboardMap.Add("FileDropList", Clipboard.get) } if (Clipboard.ContainsAudio()) { clipboardMap.Add("Audio", SerializationMethods.SerializeToByteArray(Clipboard.GetAudioStream())); } //if(Clipboard.co) return(clipboardMap); }