Skip to content

Commit

Permalink
进程名判断不正确
Browse files Browse the repository at this point in the history
  • Loading branch information
silentmoooon committed Dec 2, 2019
1 parent 90dc1c4 commit 6f9e361
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions ClipOne/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Process[] pro = Process.GetProcesses();

int n = pro.Where(p => p.ProcessName.ToLower().Equals(Process.GetCurrentProcess().MainModule.ModuleName.ToLower())).Count();
int n = pro.Where(p => (p.ProcessName.ToLower()+".exe").Equals(Process.GetCurrentProcess().MainModule.ModuleName.ToLower())).Count();
if (n > 1)
{

Expand Down
6 changes: 4 additions & 2 deletions ClipOne/service/ClipService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ public void SetValueToClipboard(ClipModel result)
{
bool isExplorer = false;
Process[] ps = Process.GetProcesses();
WinAPIHelper.GetWindowThreadProcessId(WinAPIHelper.GetForegroundWindow(), out int pid);

WinAPIHelper.GetWindowThreadProcessId(WinAPIHelper.GetForegroundWindow(), out int pid);

foreach (Process p in ps)
{

if (p.Id == pid && p.ProcessName.ToLower() == "explorer")
{
isExplorer = true;
Expand All @@ -110,7 +112,7 @@ public void SetValueToClipboard(ClipModel result)
//如果是桌面或者资源管理器则直接粘贴为文件
if (isExplorer)
{

string[] tmp = Path.GetFullPath(result.ClipValue).Split(',');

IDataObject data = new DataObject(DataFormats.FileDrop, tmp);
Expand Down
3 changes: 3 additions & 0 deletions ClipOne/util/WinAPIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,8 @@ int nMaxCount //最大值
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);

[DllImport("user32.dll", EntryPoint = "keybd_event", SetLastError = true)]
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

}
}
11 changes: 8 additions & 3 deletions ClipOne/view/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -689,13 +690,17 @@ private void SetValueToClip(ClipModel result)
catch { }
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);//按下
//WinAPIHelper.keybd_event((byte)KeyInterop.VirtualKeyFromKey(Key.V),0,2,0);//弹起
//WinAPIHelper.keybd_event((byte)KeyInterop.VirtualKeyFromKey(Key.LeftCtrl), 0,2,0);//弹起

KeyboardKit.Keyboard.Press(Key.LeftCtrl);
KeyboardKit.Keyboard.Press( Key.V);
KeyboardKit.Keyboard.Press(Key.V);

KeyboardKit.Keyboard.Release(Key.LeftCtrl);
KeyboardKit.Keyboard.Release(Key.V);


}

Expand Down

0 comments on commit 6f9e361

Please sign in to comment.