Skip to content

Commit

Permalink
增加鼠标中键功能,中键点击条目设置到剪切板但不触发粘贴,方便在一些特殊场景下使用.
Browse files Browse the repository at this point in the history
  • Loading branch information
silentmoooon committed Apr 9, 2020
1 parent 8c2068e commit 47f2d28
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
15 changes: 15 additions & 0 deletions html/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ function mouseup(e) {
}
pasteValue(e.getAttribute("index") / 1, sendToTop);
}
}else if (event.button==1){
setToClipBoard(e.getAttribute("index") / 1);
}

}
Expand Down Expand Up @@ -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 = [];
Expand Down
42 changes: 30 additions & 12 deletions view/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{

Expand Down Expand Up @@ -657,8 +660,23 @@ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs
}


}
}

/// <summary>
/// 将粘贴条目设置到剪切板
/// </summary>
/// <param name="id">索引</param>
public void SetToClipboard(string clipStr)
{
Hide();

ClipModel clip = JsonConvert.DeserializeObject<ClipModel>(HttpUtility.UrlDecode(clipStr));


clipService.SetValueToClipboard(clip);


}
/// <summary>
/// 根据索引粘贴条目到活动窗口
/// </summary>
Expand All @@ -682,23 +700,23 @@ public void PasteValue(string clipStr)
/// /// <param name="neadPause">是否需要延时,单条需要,批量不需要</param>
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);//按下
Expand All @@ -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);



Expand Down

0 comments on commit 47f2d28

Please sign in to comment.