77 lines
2.9 KiB
C#
77 lines
2.9 KiB
C#
using AllBase;
|
|
using CefSharp;
|
|
using CefSharp.WinForms;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace _29WxOrder.Helper
|
|
{
|
|
public class CEFHelper
|
|
{
|
|
// 鼠标左键按下,移动,移动...左键抬起。
|
|
public static void CefMouseDrag(ChromiumWebBrowser webBrowser, int x1, int y1, int x2, int y2)
|
|
{
|
|
Thread.Sleep(100);
|
|
var host = webBrowser.GetBrowser().GetHost();
|
|
|
|
var rx = -6 + Randomx.GetId(13);
|
|
x2 = x2 + rx;
|
|
// 随机按下点的位置(正负6像素),提高仿真性
|
|
int x = x1 + rx;
|
|
int y = y1 - 6 + Randomx.GetId(13);
|
|
|
|
// 按下鼠标左键
|
|
host.SendMouseClickEvent(x, y, MouseButtonType.Left, false, 1, CefEventFlags.None);
|
|
Thread.Sleep(100 + Randomx.GetId(300));
|
|
|
|
// 滑动光标
|
|
int times = -20;
|
|
while (x < x2 + 4 - Randomx.GetId(9))
|
|
{
|
|
times++;
|
|
x += (25 + Randomx.GetId(15)) / 8;
|
|
if (times % 5 == 0)
|
|
y = y - 1 + Randomx.GetId(3);
|
|
Thread.Sleep(6 + Math.Abs(times) / 5 + Randomx.GetId(16));
|
|
host.SendMouseMoveEvent((int)x, (int)y, false, CefEventFlags.LeftMouseButton);
|
|
}
|
|
if (x < x2 - 1)
|
|
while (x < x2)
|
|
{
|
|
times++;
|
|
x += (8 + Randomx.GetId(8)) / 8;
|
|
if (times % 5 == 0)
|
|
y = y - 1 + Randomx.GetId(3);
|
|
Thread.Sleep(6 + Math.Abs(times) / 5 + Randomx.GetId(16));
|
|
host.SendMouseMoveEvent((int)x, (int)y, false, CefEventFlags.LeftMouseButton);
|
|
}
|
|
else if (x > x2 + 1)
|
|
while (x > x2)
|
|
{
|
|
times++;
|
|
x -= (8 + Randomx.GetId(8)) / 8;
|
|
if (times % 5 == 0)
|
|
y = y - 1 + Randomx.GetId(3);
|
|
Thread.Sleep(6 + Math.Abs(times) / 5 + Randomx.GetId(16));
|
|
host.SendMouseMoveEvent((int)x, (int)y, false, CefEventFlags.LeftMouseButton);
|
|
}
|
|
|
|
// 如果最后位置偏差较多,再做一次调整
|
|
x = x2 - 1 + Randomx.GetId(3);
|
|
x = x2;
|
|
Thread.Sleep(18 + Math.Abs(times) / 5 + Randomx.GetId(16));
|
|
Thread.Sleep(18 + Math.Abs(times) / 5 + Randomx.GetId(16));
|
|
host.SendMouseMoveEvent((int)x, (int)y, false, CefEventFlags.LeftMouseButton);
|
|
|
|
// 抬起鼠标左键
|
|
Thread.Sleep(300 + Randomx.GetId(500));
|
|
host.SendMouseClickEvent(x, y, MouseButtonType.Left, true, 1, CefEventFlags.None);
|
|
host.SendMouseClickEvent(x, y, MouseButtonType.Left, true, 1, CefEventFlags.None);
|
|
}
|
|
}
|
|
}
|