public void DumpWFClipboardTest() { TestContext.WriteLine($"ContainsAudio: {WFClipboard.ContainsAudio()}"); TestContext.WriteLine($"ContainsData: {WFClipboard.ContainsData(DataFormats.StringFormat)}"); TestContext.WriteLine($"ContainsFileDropList: {WFClipboard.ContainsFileDropList()}"); TestContext.WriteLine($"ContainsImage: {WFClipboard.ContainsImage()}"); TestContext.WriteLine($"ContainsText: {WFClipboard.ContainsText()}"); TestContext.WriteLine($"GetAudioStream: {WFClipboard.GetAudioStream()}"); TestContext.WriteLine($"GetData: {WFClipboard.GetData(DataFormats.StringFormat)}"); TestContext.WriteLine($"GetDataObject: {WFClipboard.GetDataObject()}"); TestContext.WriteLine($"GetFileDropList: {string.Join("\n", WFClipboard.GetFileDropList().Cast<string>())}"); TestContext.WriteLine($"GetImage: {WFClipboard.GetImage()}"); TestContext.WriteLine($"GetText: {WFClipboard.GetText()}"); }
public static bool ContainsImage() { return(ClipboardProxy.ContainsImage()); }
public void SaveClipboardToRecent() { Console.WriteLine("attempting to save clipboard to recent"); if (!selfCopy) { Console.WriteLine("checking for recent duplicate"); ClipboardObject duplicateObject = null; foreach (ClipboardObject clipboardObject in categories[0].ClipboardObjects) { if (clipboardObject.MatchesClipboard()) { duplicateObject = clipboardObject; break; } } if (duplicateObject != null) { Console.WriteLine("moving duplicate clipboard to most recent"); categories[0].RemoveClipboardObject(duplicateObject); if (CurrentCategoryId == categories[0].Id) { ContentPanel.Children.Remove(duplicateObject.ClipboardContainer); } duplicateObject.Name = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); categories[0].AddClipboardObject(duplicateObject); if (CurrentCategoryId == categories[0].Id) { ContentPanel.Children.Insert(1, duplicateObject.ClipboardContainer); } } else { ClipboardObject newClipboardObject = null; Console.WriteLine("not a duplicate, finding format to save as"); foreach (string format in Clipboard.GetDataObject().GetFormats()) { Console.WriteLine(format); } if (Clipboard.ContainsText()) { newClipboardObject = new TextClipboardObject(this, DateTime.Now.ToString(Recent.DATE_FORMAT), Clipboard.GetText()); } else if (Clipboard.ContainsImage()) { newClipboardObject = new ImageClipboardObject(this, DateTime.Now.ToString(Recent.DATE_FORMAT), Clipboard.GetDataObject()); } else if (Clipboard.ContainsFileDropList()) { newClipboardObject = new FileDropListClipboardObject(this, DateTime.Now.ToString(Recent.DATE_FORMAT), Clipboard.GetFileDropList()); } if (newClipboardObject != null) { categories[0].AddClipboardObject(newClipboardObject); if (CurrentCategoryId == categories[0].Id) { ContentPanel.Children.Insert(1, newClipboardObject.ClipboardContainer); } if (categories[0].ClipboardObjects.Count() > MAX_RECENTS) { categories[0].RemoveClipboardObject(categories[0].ClipboardObjects.Last()); if (CurrentCategoryId == categories[0].Id) { ContentPanel.Children.RemoveAt(categories[0].ClipboardObjects.Count() + 1); } } } } SetActiveCategory(Recent.ID); } else { Console.WriteLine("ignoring self copy"); selfCopy = false; } }
public bool ContainsImage() { return(WindowsClipboard.ContainsImage()); }
static void Main(string[] args) { PathType pathType = PathType.None; string parsedPath = null; var screenBounds = Screen.PrimaryScreen.Bounds; GImgClicks gimgClicks = null; foreach (var supported in GImgClicksSupported) { if (supported.ScreenResolution.Width == screenBounds.Width && supported.ScreenResolution.Height == screenBounds.Height) { gimgClicks = supported; break; } } if (gimgClicks == null) { MessageBox.Show("Error: Screen resolution not supported.", "GoSearch"); return; } Utility.RunAsSTAThread(() => { if (Clipboard.ContainsText()) { var s = Clipboard.GetText(); if (s.StartsWith("http://") || s.StartsWith("https://")) { pathType = PathType.WebUrl; return; } else if (File.Exists(s)) { pathType = PathType.LocalFile; return; } } // Note The WPF version of Clipboard.GetImage() is buggy if (Clipboard.ContainsImage()) { var image = Clipboard.GetImage(); parsedPath = Path.Combine(Path.GetTempPath(), "temp-gs.png"); pathType = PathType.LocalFile; image.Save(parsedPath, System.Drawing.Imaging.ImageFormat.Png); return; } if (Clipboard.ContainsFileDropList()) { var fs = Clipboard.GetFileDropList(); parsedPath = fs[0]; pathType = PathType.LocalFile; } }); if (pathType == PathType.None) { MessageBox.Show("Error: No valid path copied.", "GoSearch"); return; } var w = new ControlledWindow { ProcessPath = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", Arguments = @"-inprivate http://images.google.com" }; void SleepAndCheck(int sleepMs = 500) { Thread.Sleep(500); if (w.Process.HasExited) { throw new TargetWindowExited(); } } if (!w.CreateNew(x => x.StartsWith("Google Images"))) { MessageBox.Show("Error: Failed to create new browser window.", "GoSearch"); return; } try { if (!w.Process.HasExited && w.WindowRect.HasValue) { if (!w.WaitUntilTitleStartsWith("Google Images")) { MessageBox.Show("Error: Failed to load Google Images site.", "GoSearch"); return; } if (w.Process.HasExited) { return; } //var bounds = System.Windows.Forms.Screen.PrimaryScreen.Bounds; //const int StandardResolutionWidth = 1920; //const int StandardResolutionHeight = 1080; //const int StandardClickX = 1200; //const int StandardClickY = 550; //if (bounds.Width == StandardResolutionHeight && bounds.Height == StandardResolutionWidth) //{ // Input.MouseClick(1200, 550); //} //else //{ // var x = StandardClickX * bounds.Width / StandardResolutionWidth; // var y = StandardClickY * bounds.Height / StandardResolutionHeight; // Input.MouseClick(x, y); //} Input.MouseClick(gimgClicks.CameraButton.X, gimgClicks.CameraButton.Y); SleepAndCheck(); if (w.Process.HasExited) { return; } if (pathType == PathType.WebUrl) { Debug.Assert(parsedPath == null); CtrlV(); } else if (pathType == PathType.LocalFile) { Input.MouseClick(gimgClicks.UploadImageTab.X, gimgClicks.UploadImageTab.Y); SleepAndCheck(); Input.MouseClick(gimgClicks.ChooseFileButton.X, gimgClicks.ChooseFileButton.Y); SleepAndCheck(); if (parsedPath != null) { Input.TypeStr("\"" + parsedPath + "\"\n"); } else { CtrlV(); } } } } catch (TargetWindowExited) { MessageBox.Show("Error: Search window lost.", "GoSearch"); } }
void GetClipboardContents() { if (_image) { if (WinFormsClipboard.ContainsImage()) { _result = WinFormsClipboard.GetImage(); } return; } if (_audio) { if (WinFormsClipboard.ContainsAudio()) { _result = WinFormsClipboard.GetAudioStream(); } return; } if (_files) { if (WinFormsClipboard.ContainsFileDropList()) { StringCollection paths = WinFormsClipboard.GetFileDropList(); List <FileSystemInfo> infos = new List <FileSystemInfo>(); foreach (string p in paths) { if (File.Exists(p)) { infos.Add(new FileInfo(p)); } else if (Directory.Exists(p)) { infos.Add(new DirectoryInfo(p)); } } _result = infos.ToArray(); } return; } if (_html) { if (WinFormsClipboard.ContainsText(TextDataFormat.Html)) { string content = WinFormsClipboard.GetText(TextDataFormat.Html); RegexOptions regexOptions = RegexOptions.Singleline | RegexOptions.IgnoreCase; if (_html && _htmlFragment) { Regex regex = new Regex("<!--StartFragment-->(.*)<!--EndFragment-->", regexOptions); Match match = regex.Match(content); if (match.Success) { content = match.Groups[1].Value; } } else if (_html) { Regex regex = new Regex(".*?(<HTML>.*)", regexOptions); Match match = regex.Match(content); if (match.Success) { content = match.Groups[1].Value; } } _result = content; return; } return; } if (WinFormsClipboard.ContainsText()) { _result = WinFormsClipboard.GetText(RequestedTextFormat); return; } }