diff --git a/html/js/main.js b/html/js/main.js index 985901e..11c909b 100644 --- a/html/js/main.js +++ b/html/js/main.js @@ -332,6 +332,8 @@ function mouseup(e) { } pasteValue(e.getAttribute("index") / 1, sendToTop); } + }else if (event.button==1){ + setToClipBoard(e.getAttribute("index") / 1); } } @@ -419,6 +421,19 @@ function pasteValue(index, sendToTop) { displayData(); } + +//设置到剪切板但不粘贴 +function setToClipBoard(index,) { + var obj = clipObj[index]; + clipObj.splice(index, 1)[0]; + clipObj.splice(0, 0, obj); + + window.external.notify( + "SetToClipBoard|" + encodeURIComponent(JSON.stringify(obj)) + ); + + displayData(); +} //粘贴多条 function pasteMultiValue() { var clipList = []; diff --git a/view/MainWindow.xaml.cs b/view/MainWindow.xaml.cs index 698e21d..7ad86de 100644 --- a/view/MainWindow.xaml.cs +++ b/view/MainWindow.xaml.cs @@ -172,6 +172,9 @@ private void WebView1_ScriptNotify(object sender, WebViewControlScriptNotifyEven PasteValueList(args[1]); } + else if (args[0]== "SetToClipBoard"){ + SetToClipboard(args[1]); + } else if (args[0] == "DeleteImage") { @@ -657,8 +660,23 @@ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs } - } + } + + /// + /// 将粘贴条目设置到剪切板 + /// + /// 索引 + public void SetToClipboard(string clipStr) + { + Hide(); + ClipModel clip = JsonConvert.DeserializeObject(HttpUtility.UrlDecode(clipStr)); + + + clipService.SetValueToClipboard(clip); + + + } /// /// 根据索引粘贴条目到活动窗口 /// @@ -682,23 +700,23 @@ public void PasteValue(string clipStr) /// /// 是否需要延时,单条需要,批量不需要 private void SetValueToClip(ClipModel result) { - + try { - clipService.SetValueToClipboard(result); + clipService.SetValueToClipboard(result); } - catch (Exception e){ - //Console.WriteLine(e.StackTrace); - //IntPtr hwnd = WinAPIHelper.GetOpenClipboardWindow(); - //StringBuilder sb = new StringBuilder(501); - //WinAPIHelper.GetWindowText(hwnd, sb, 500); - //Console.WriteLine("=="); - //Console.WriteLine(sb.ToString()); + catch (Exception e){ + //Console.WriteLine(e.StackTrace); + //IntPtr hwnd = WinAPIHelper.GetOpenClipboardWindow(); + //StringBuilder sb = new StringBuilder(501); + //WinAPIHelper.GetWindowText(hwnd, sb, 500); + //Console.WriteLine("=="); + //Console.WriteLine(sb.ToString()); //Console.WriteLine("=="); } - Thread.Sleep(50); + Thread.Sleep(50); //WinAPIHelper.keybd_event((byte)KeyInterop.VirtualKeyFromKey(Key.LeftCtrl),0,0,0);//按下 //WinAPIHelper.keybd_event((byte)KeyInterop.VirtualKeyFromKey(Key.V),0,0,0);//按下 @@ -709,7 +727,7 @@ private void SetValueToClip(ClipModel result) KeyboardKit.Keyboard.Press(Key.V); KeyboardKit.Keyboard.Release(Key.LeftCtrl); - KeyboardKit.Keyboard.Release(Key.V); + KeyboardKit.Keyboard.Release(Key.V);