static void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo)
{
int x = dx, y = dy;
edit_position(dwFlags, dx, dy, ref x, ref y);
IntPtr hWndFromPoint = WindowFromPoint(x, y);
screen_to_client(hWndFromPoint, ref x, ref y);
send_message(hWndFromPoint, dwFlags, cButtons, x, y);
}
static void edit_position(int dwFlags, int dx, int dy, ref int x, ref int y)
{
Point pos = MousePosition;
x = x + pos.X;
y = y + pos.Y;
if ((dwFlags | MOUSEEVENTF_ABSOLUTE) == dwFlags)
SetCursorPos(dx, dy);
if ((dwFlags | MOUSEEVENTF_MOVE) == dwFlags)
SetCursorPos(x, y);
}
static void send_message(IntPtr hWnd, int dwFlags, int cButtons, int x, int y)
{
if ((dwFlags | MOUSEEVENTF_LEFTDOWN) == dwFlags)
SendMessage(hWnd, WM_LBUTTONDOWN, cButtons, MakeDWord(x, y));
if ((dwFlags | MOUSEEVENTF_LEFTUP) == dwFlags)
SendMessage(hWnd, WM_LBUTTONUP, cButtons, MakeDWord(x, y));
if ((dwFlags | MOUSEEVENTF_RIGHTDOWN) == dwFlags)
SendMessage(hWnd, WM_RBUTTONDOWN, cButtons, MakeDWord(x, y));
if ((dwFlags | MOUSEEVENTF_RIGHTUP) == dwFlags)
SendMessage(hWnd, WM_RBUTTONUP, cButtons, MakeDWord(x, y));
if ((dwFlags | MOUSEEVENTF_MIDDLEDOWN) == dwFlags)
SendMessage(hWnd, WM_MBUTTONDOWN, cButtons, MakeDWord(x, y));
if ((dwFlags | MOUSEEVENTF_MIDDLEUP) == dwFlags)
SendMessage(hWnd, WM_MBUTTONUP, cButtons, MakeDWord(x, y));
}
static int MakeDWord(int low, int high)
{
return low + (high * Abs(~ushort.MaxValue));
}
static int Abs(int value)
{
return ((value >> 31) ^ value) - (value >> 31);
}
MakeDWord / 合并整数,函数主要是把两个short合并为一个int,分为low、high两部分
static bool screen_to_client(IntPtr hwnd, ref int x, ref int y)
{
bool bRetVal = false;
Point lpptPos = new Point(x, y);
if ((bRetVal = ScreenToClient(hwnd, ref lpptPos)))
{
x = lpptPos.X;
y = lpptPos.Y;
}
return bRetVal;
}
screen_to_client函数故名思意,它主要用于把屏幕上的坐标转换到窗口客户上对应坐标
public const int WM_LBUTTONDOWN = 513; // 鼠标左键按下
public const int WM_LBUTTONUP = 514; // 鼠标左键抬起
public const int WM_RBUTTONDOWN = 516; // 鼠标右键按下
public const int WM_RBUTTONUP = 517; // 鼠标右键抬起
public const int WM_MBUTTONDOWN = 519; // 鼠标中键按下
public const int WM_MBUTTONUP = 520; // 鼠标中键抬起
public const int MOUSEEVENTF_MOVE = 0x0001; // 移动鼠标
public const int MOUSEEVENTF_LEFTDOWN = 0x0002; // 鼠标左键按下
public const int MOUSEEVENTF_LEFTUP = 0x0004; // 鼠标左键抬起
public const int MOUSEEVENTF_RIGHTDOWN = 0x0008; // 鼠标右键按下
public const int MOUSEEVENTF_RIGHTUP = 0x0010; // 鼠标右键抬起
public const int MOUSEEVENTF_MIDDLEDOWN = 0x0020; // 鼠标中键按下
public const int MOUSEEVENTF_MIDDLEUP = 0x0040; // 鼠标中键抬起
public const int MOUSEEVENTF_ABSOLUTE = 0x8000; // 绝对坐标
[DllImport("user32.dll", SetLastError = true)]
public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, int lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr WindowFromPoint(int xPoint, int yPoint);
[DllImport("user32.dll", SetLastError = true)]
public static extern int SetCursorPos(int x, int y);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool ScreenToClient(IntPtr hWnd, ref Point lppt);
// [DllImport("user32", SetLastError = true)]
// public static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有