public override void Spellcast() { if (!Form1.isRunning) { return; } Point p = MouseKeyHook.TransferCoordinate(MouseKeyHook.GetWindowHandle(targetWinInfo.TargetWindowTitle), targetWinInfo.WindowPosition); }
public override void Spellcast() { //if (!Form1.isRunning) return; var sim = new InputSimulator(); Point p = MouseKeyHook.TransferCoordinate(MouseKeyHook.GetWindowHandle(targetWinInfo.TargetWindowTitle), targetWinInfo.WindowPosition); MouseKeyHook.mouseMoveTo(sim, p); sim.Mouse .LeftButtonClick(); }
public static Point TransferCoordinate(IntPtr hwnd, int loc_x, int loc_y) { RECT rc = new RECT(); MouseKeyHook.GetWindowRect(hwnd, ref rc); int width = rc.Right - rc.Left; //窗口的宽度 int height = rc.Bottom - rc.Top; //窗口的高度 int x = rc.Left; int y = rc.Top; if (loc_x > width || loc_y > height) { throw new Exception("警告,窗口大小小于设定值!"); } return(new Point(x + loc_x, y + loc_y)); }
private void OnMouseClick(object sender, MouseEventArgs e) { clickElf.targetWinInfo.TargetWindowHandle = MouseKeyHook.GetForegroundWindow(); RECT rc = new RECT(); MouseKeyHook.GetWindowRect(clickElf.targetWinInfo.TargetWindowHandle, ref rc); int x = rc.Left; int y = rc.Top; clickElf.targetWinInfo.WindowPosition = new Point(e.X - x, e.Y - y);; StringBuilder s = new StringBuilder(512); int i = MouseKeyHook.GetWindowText(clickElf.targetWinInfo.TargetWindowHandle.ToInt32(), s, s.Capacity); clickElf.targetWinInfo.TargetWindowTitle = s.ToString(); UpdateInfo(); Unsubscribe(); }
public static IntPtr GetWindowHandle(string winName) { IntPtr hwnd = new IntPtr(0); if (winName.Length > 0) { hwnd = MouseKeyHook.FindWindow(null, winName); if (hwnd.ToInt32() != 0) { return(hwnd); } else { foreach (var i in MouseKeyHook.GetAllDesktopWindows()) { if (i.szWindowName.IndexOf(winName) >= 0) { return(i.hWnd); } } } } return(hwnd); }