private void SetHotkey(object sender, RoutedEventArgs e) { if (Clipboard.IsHistoryEnabled() && HkTextBox.Hotkey != null) { string[] modifiers = HkTextBox.Hotkey.Modifiers.ToString().Split(',').OrderByDescending(d => d == "Control").ThenBy(a => a).ToArray(); //Following Ctrl + Shift + Alt Ordering Convention string hotkey = $"{ (modifiers[0] == "None" ? "" : string.Join(" + ", modifiers) + " + ") } {HkTextBox.Hotkey.Key}"; try { using (LiteDatabase db = new LiteDatabase(Path.Combine(documents, "Auto Paste Clipboard", "data.db"))) { ILiteCollection <Hotkey> collection = db.GetCollection <Hotkey>("hotkey"); if (collection.Count() > 0) { collection.DeleteAll(); } collection.Insert(HkTextBox.Hotkey); } HotkeyManager.Current.AddOrReplace("Paste", HkTextBox.Hotkey.Key, HkTextBox.Hotkey.Modifiers, AutoPaste); MessageBox.Show($"{hotkey} has been successfully set as the hotkey.", "Info", MessageBoxButton.OK, MessageBoxImage.Information); WindowState = WindowState.Minimized; } catch (HotkeyAlreadyRegisteredException) { MessageBox.Show($"{hotkey} is being used by another application.", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation); } } else { MessageBox.Show("You must enable clipboard history on windows settings and set a hotkey.", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }
public Clipboard() { if (!Cp.IsHistoryEnabled()) { Console.WriteLine("[+] Turning on clipboard history feature..."); try { var rk = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Clipboard", true); if (rk == null) { Console.WriteLine( "[!] Clipboard history feature not available on target! Target needs to be at least Win10 Build 1809.\n[!] Exiting...\n"); return; } rk.SetValue("EnableClipboardHistory", "1", RegistryValueKind.DWord); } catch (Exception ex) { Console.WriteLine(ex); } } Cp.ContentChanged += async(s, e) => { DataPackageView dataPackageView = Cp.GetContent(); foreach (var availableFormat in dataPackageView.AvailableFormats) { Console.WriteLine(availableFormat); } var a = await Cp.GetHistoryItemsAsync(); var b = a.Items; foreach (var it in b) { Console.WriteLine(it.Timestamp); } if (dataPackageView.Contains(StandardDataFormats.Text)) { string text = await dataPackageView.GetTextAsync(); Console.WriteLine(text); } }; Cp.HistoryChanged += async(s, e) => { Console.WriteLine("History Changed!"); }; }