通过“钩子”去到要抓取的定点xy,并转换成句柄,然后通过api获取想要的值。
代码如下
1、首先定义一个MouseHook 类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Windows.Forms;
namespace Demo
{
class MouseHook
{
private Point point;
private Point Point
{
get { return point; }
set
{
if (point != value)
{
point = value;
if (MouseMoveEvent != null)
{
var e = new MouseEventArgs(MouseButtons.None, 0, point.X, point.Y, 0);
MouseMoveEvent(this, e);
}
}
}
}
private int hHook;
public const int WH_MOUSE_LL = 14;
public Win32Api.HookProc hProc;
public MouseHook() { this.Point = new Point(); }
public int SetHook()
{
hProc = new Win32Api.HookProc(MouseHookProc);
&nb