需要全局捕捉鼠标点击。
使用API函数或着SharpDirectX库的DirectInput都可以。
/// <summary>
/// GetAsyncKeyState函数返回的是指定虚拟键瞬时的状态值,它有四种返回值:
///<para></para>0---键未被按下,而且键也未被按过(自上次调用GetAsyncKeyState后);
///<para></para>1---键抬起瞬间,在此之前键曾经被按过;
///<para></para>-32768(即16进制数&H8000) --- 键按下瞬间,但在此之前键未被按过;
///<para></para>-32767(即16进制数&H8001) --- 键按下持续,在此之前键也曾经被按过。
/// </summary>
/// <param name="vKey"></param>
/// <returns></returns>
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int GetAsyncKeyState ( int vKey );
/// <summary>
/// 获取鼠标指针位置
/// </summary>
/// <param name="lpPoint"></param>
/// <returns></returns>
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int GetCursorPos (ref MOUSEPOINT lpPoint );
//鼠标按键的虚拟码
None = 0,
鼠标左键 = 1, LButton = 0x1,
鼠标右键 = 2, RButton = 0x2,
取消 = 3, Cancel = 0x3,
鼠标中键 = 4, MButton = 0x4,
鼠标侧键1 = 5, XButton1 = 0x5,
鼠标侧键2 = 6, XButton2 = 0x6,