/// <summary> /// Copies text into the clipboard. If the Silverlight runtime on the /// system does not support the clipboard API, then it reverts to a /// large text box that allows the user to manually copy and paste. /// </summary> /// <param name="text">The text to set.</param> private void SetClipboardText(string text) { if (_clipboardFeatureSupported == null) { _clipboardFeatureSupported = ClipboardHelper.IsClipboardFeatureSupported; } bool useAlternative = true; if (_clipboardFeatureSupported == true) { try { ClipboardHelper.SetText(text); useAlternative = false; } catch (SecurityException) { useAlternative = true; } } if (useAlternative) { ClipboardContents.Text = text; ClipboardHelperGrid.Visibility = Visibility.Visible; ClipboardContents.SelectAll(); ClipboardContents.Focus(); } }
private static void Send(ISiEngine siEngine, List <SiEvent> l) { bool bHasClipOp = l.Exists(SendInputEx.IsClipboardOp); ClipboardEventChainBlocker cev = null; ClipboardContents cnt = null; if (bHasClipOp) { cev = new ClipboardEventChainBlocker(); cnt = new ClipboardContents(true, true); } try { SendPriv(siEngine, l); } finally { if (bHasClipOp) { Clipboard.Clear(); cnt.SetData(); cev.Dispose(); } } }
public async void SaveScreenshot(ClipboardContents clipboard = ClipboardContents.URL, bool openURL = false) { int shotNumber = 0; Directory.CreateDirectory("Screenshots"); string path = Path.Combine(Application.StartupPath, "Screenshots", "photovs_screenshot_" + shotNumber.ToString().PadLeft(3, '0') + ".png"); while (File.Exists(path)) { shotNumber++; path = Path.Combine(Application.StartupPath, "Screenshots", "photovs_screenshot_" + shotNumber.ToString().PadLeft(3, '0') + ".png"); } using (FileStream fs = new FileStream(path, FileMode.Create)) { Console.WriteLine("Copied to clipboard and saved screenshot to ", path); renderTarget2.SaveAsPng(fs, GAME_WIDTH, GAME_HEIGHT); } using (MemoryStream mem = new MemoryStream()) { // save game screenshot to memory renderTarget2.SaveAsPng(mem, GAME_WIDTH, GAME_HEIGHT); using (var w = new WebClient()) { // upload to Imgur // oh yeah, you all can see this too. oh well. string clientID = "36e2260c96b7e67"; w.Headers.Add("Authorization", "Client-ID " + clientID); var values = new NameValueCollection { { "image", Convert.ToBase64String(mem.GetBuffer()) } }; byte[] response = w.UploadValues("https://api.imgur.com/3/upload.xml", values); // parse through XML and get a link back using (MemoryStream res = new MemoryStream(response)) { var xml = XDocument.Load(res); var data = xml.Descendants("data"); foreach (var d in data) { var val = d.Element("link").Value; if (clipboard == ClipboardContents.Image) { Clipboard.SetImage(System.Drawing.Image.FromFile(path)); } else { Clipboard.SetText(val); } Console.WriteLine($"Screenshot uploaded to {val}"); // send to discord using (WebClient client = new WebClient()) { HttpResponseMessage resp = await new HttpClient().PostAsync("https://discordapp.com/api/webhooks/482641656361910272/ZKZfPujN8SfUBznuwqLUu_HJ2o-58ws_r5Whd3bcOalT2woGmjMTYAbwK7zuqFXY0rIl", new StringContent("{\"embeds\":[{\"image\":{\"url\":\"" + val + "\"}}]}", Encoding.UTF8, "application/json")); //Console.WriteLine(resp.ToString()); Console.WriteLine("Screenshot posted in PhotoVs Discord"); } if (openURL) { try { Process.Start(val); } catch (System.ComponentModel.Win32Exception) { Process.Start("IExplore.exe", val); } } } } } } }