मैंने सी # और एक साधारण वेब ब्राउजर नियंत्रण का उपयोग करके कई बॉट बनाए हैं। आमतौर पर मैं एक कर्सर को सिमुलेट करने और एक क्लिक का आह्वान करने के उपयोग के बिना किसी तत्व पर "क्लिक" फ़ंक्शन को स्वचालित करने का प्रयास करता हूं।
उदाहरण:
webBrowser1.Document.GetElementById("elementid").InvokeMember("Click");
मुझे लगता है यह बहुत आसान है वास्तव में एक कर्सर का अनुकरण, हालांकि एक कर्सर का अनुकरण भी अपेक्षाकृत आसानी से हासिल कर सकते हैं, यहाँ कोड मैं आमतौर पर का उपयोग करना है से:
//Example of how to use it:
Point controlLoc = this.PointToScreen(webbrowser1.Location);
controlLoc.X = controlLoc.X + webbrowser1.Document.GetElementById("elementid").OffsetRectangle.Left;
controlLoc.Y = controlLoc.Y + webbrowser1.Document.GetElementById("elementid").OffsetRectangle.Top;
Cursor.Position = controlLoc;
MouseSimulator.ClickLeftMouseButton();
public class MouseSimulator
{
[DllImport("user32.dll", SetLastError = true)]
static extern uint SendInput(uint nInputs, ref INPUT pInputs, int cbSize);
[StructLayout(LayoutKind.Sequential)]
struct INPUT
{
public SendInputEventType type;
public MouseKeybdhardwareInputUnion mkhi;
}
[StructLayout(LayoutKind.Explicit)]
struct MouseKeybdhardwareInputUnion
{
[FieldOffset(0)]
public MouseInputData mi;
[FieldOffset(0)]
public KEYBDINPUT ki;
[FieldOffset(0)]
public HARDWAREINPUT hi;
}
[StructLayout(LayoutKind.Sequential)]
struct KEYBDINPUT
{
public ushort wVk;
public ushort wScan;
public uint dwFlags;
public uint time;
public IntPtr dwExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
struct HARDWAREINPUT
{
public int uMsg;
public short wParamL;
public short wParamH;
}
struct MouseInputData
{
public int dx;
public int dy;
public uint mouseData;
public MouseEventFlags dwFlags;
public uint time;
public IntPtr dwExtraInfo;
}
[Flags]
enum MouseEventFlags : uint
{
MOUSEEVENTF_MOVE = 0x0001,
MOUSEEVENTF_LEFTDOWN = 0x0002,
MOUSEEVENTF_LEFTUP = 0x0004,
MOUSEEVENTF_RIGHTDOWN = 0x0008,
MOUSEEVENTF_RIGHTUP = 0x0010,
MOUSEEVENTF_MIDDLEDOWN = 0x0020,
MOUSEEVENTF_MIDDLEUP = 0x0040,
MOUSEEVENTF_XDOWN = 0x0080,
MOUSEEVENTF_XUP = 0x0100,
MOUSEEVENTF_WHEEL = 0x0800,
MOUSEEVENTF_VIRTUALDESK = 0x4000,
MOUSEEVENTF_ABSOLUTE = 0x8000
}
enum SendInputEventType : int
{
InputMouse,
InputKeyboard,
InputHardware
}
public static void ClickLeftMouseButton()
{
INPUT mouseDownInput = new INPUT();
mouseDownInput.type = SendInputEventType.InputMouse;
mouseDownInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_LEFTDOWN;
SendInput(1, ref mouseDownInput, Marshal.SizeOf(new INPUT()));
INPUT mouseUpInput = new INPUT();
mouseUpInput.type = SendInputEventType.InputMouse;
mouseUpInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_LEFTUP;
SendInput(1, ref mouseUpInput, Marshal.SizeOf(new INPUT()));
}
यह लोड किए गए वेब ब्राउजर नियंत्रण में "एलिमेंटिड" नामक किसी भी तत्व पर बायाँ क्लिक करेगा। सूचना अन्य MouseEventFlags कि आसानी से लागू किया जा सकता है:
यहाँ सही क्लिक के लिए एक उदाहरण है:
public static void ClickRightMouseButton()
{
INPUT mouseDownInput = new INPUT();
mouseDownInput.type = SendInputEventType.InputMouse;
mouseDownInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_RIGHTDOWN;
SendInput(1, ref mouseDownInput, Marshal.SizeOf(new INPUT()));
INPUT mouseUpInput = new INPUT();
mouseUpInput.type = SendInputEventType.InputMouse;
mouseUpInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_RIGHTUP;
SendInput(1, ref mouseUpInput, Marshal.SizeOf(new INPUT()));
}
वहां भी इसी तरह पोस्ट यहाँ है http://stackoverflow.com/questions/1964529/online-trading-bot जिसमें पोकर बॉट बनाने के लिए एक लिंक है http://www.codingthewheel.com/archives/how-i-built-a-working-poker-bot। जाहिर है, मैं इसी तरह के smtn करना चाहता हूँ लेकिन अगर मैं इन दिनों बेहतर उपकरण हैं तो मैं उत्सुक हूं। और भले ही भेजा गया डेटा प्राप्त करना और प्राप्त करना आसान हो, स्क्रीन को देखकर और फिर कंप्यूटर को ले जाने से माउस अधिक सामान्य हो जाता है। –
ऐसा लगता है कि यह करने का एक तरीका भी हो सकता है http://www.mjtnet.com/blog/2006/10/11/see-the-screen-with-image-recognition/ –