Thursday 9 May 2013 photo 1/3
![]() ![]() ![]() |
här har du en "color bot" algorithm i c# som kanske sparar dig lite tid och ork.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using System.Diagnostics;
using System.Globalization;
//MusKlick DllImport
[DllImport("user32.dll")]
static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData,
int dwExtraInfo);
public enum MouseEventFlags : uint
{
LEFTDOWN = 0x00000002,
LEFTUP = 0x00000004,
MIDDLEDOWN = 0x00000020,
MIDDLEUP = 0x00000040,
MOVE = 0x00000001,
ABSOLUTE = 0x00008000,
RIGHTDOWN = 0x00000008,
RIGHTUP = 0x00000010,
WHEEL = 0x00000800,
XDOWN = 0x00000080,
XUP = 0x00000100
}
//MusKlick med antibann
private void MouseClick1()
{
Thread.Sleep((new Random()).Next(100, 130));
mouse_event((uint)MouseEventFlags.LEFTDOWN, 0, 0, 0, 0);
Thread.Sleep((new Random()).Next(50, 80));
mouse_event((uint)MouseEventFlags.LEFTUP, 0, 0, 0, 0);
}
//Tar en screenshot
private Bitmap Screenshot()
{
Bitmap bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(bmpScreenshot);
g.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size);
return bmpScreenshot;
}
//Hittar bilden och mus positionen
private bool FindBitmap(Bitmap bmpNeedle, Bitmap bmpHaystack, out Point location)
{
for(int outerX = 0; outerX < bmpHaystack.Width - bmpNeedle.Width; outerX++)
{
for (int outerY = 0; outerY < bmpHaystack.Height - bmpNeedle.Height; outerY++)
{
for (int innerX = 0; innerX < bmpNeedle.Width; innerX++)
{
for (int innerY = 0; innerY < bmpNeedle.Height; innerY++)
{
Color cNeedle = bmpNeedle.GetPixel(innerX, innerY);
Color cHaystack = bmpHaystack.GetPixel(innerX + outerX, innerY + outerY);
if (cNeedle.R != cHaystack.R || cNeedle.G != cHaystack.G || cNeedle.B != cHaystack.B)
{
goto notFound;
}
}
}
location = new Point(outerX, outerY);
return true;
notFound:
continue;
}
}
location = Point.Empty;
return false;
}
//För att leta efter "bilden/pixeln" så kör du tex Kom ihåg att ha timern på 4-5sec
private void timer1_Tick(object sender, EventArgs e)
{
Bitmap bmpScreenshot = Screenshot();
this.BackgroundImage = bmpScreenshot;
Point location;
bool success = FindBitmap(Properties.Resources.bmpLogin, bmpScreenshot, out location);
if (success)
{
Cursor.Position = location;
MouseClick1();
}
else
{
//Starta något som uppdaterar igen tex//
}
return;
}
//Start knapp
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabeld = true;
}
//Stop knapp
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabeld = false;
}
här har du en "color bot" algorithm i c# som kanske sparar dig lite tid och ork.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using System.Diagnostics;
using System.Globalization;
//MusKlick DllImport
[DllImport("user32.dll")]
static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData,
int dwExtraInfo);
public enum MouseEventFlags : uint
{
LEFTDOWN = 0x00000002,
LEFTUP = 0x00000004,
MIDDLEDOWN = 0x00000020,
MIDDLEUP = 0x00000040,
MOVE = 0x00000001,
ABSOLUTE = 0x00008000,
RIGHTDOWN = 0x00000008,
RIGHTUP = 0x00000010,
WHEEL = 0x00000800,
XDOWN = 0x00000080,
XUP = 0x00000100
}
//MusKlick med antibann
private void MouseClick1()
{
Thread.Sleep((new Random()).Next(100, 130));
mouse_event((uint)MouseEventFlags.LEFTDOWN, 0, 0, 0, 0);
Thread.Sleep((new Random()).Next(50, 80));
mouse_event((uint)MouseEventFlags.LEFTUP, 0, 0, 0, 0);
}
//Tar en screenshot
private Bitmap Screenshot()
{
Bitmap bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(bmpScreenshot);
g.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size);
return bmpScreenshot;
}
//Hittar bilden och mus positionen
{
for(int outerX = 0; outerX < bmpHaystack.Width - bmpNeedle.Width; outerX++)
{
for (int outerY = 0; outerY < bmpHaystack.Height - bmpNeedle.Height; outerY++)
{
for (int innerX = 0; innerX < bmpNeedle.Width; innerX++)
{
for (int innerY = 0; innerY < bmpNeedle.Height; innerY++)
{
Color cNeedle = bmpNeedle.GetPixel(innerX, innerY);
Color cHaystack = bmpHaystack.GetPixel(innerX + outerX, innerY + outerY);
if (cNeedle.R != cHaystack.R || cNeedle.G != cHaystack.G || cNeedle.B != cHaystack.B)
{
goto notFound;
}
}
}
location = new Point(outerX, outerY);
return true;
notFound:
continue;
}
}
location = Point.Empty;
return false;
}
//För att leta efter "bilden/pixeln" så kör du tex Kom ihåg att ha timern på 4-5sec
private void timer1_Tick(object sender, EventArgs e)
{
Bitmap bmpScreenshot = Screenshot();
this.BackgroundImage = bmpScreenshot;
Point location;
bool success = FindBitmap(Properties.Resources.bmpLogin, bmpScreenshot, out location);
if (success)
{
Cursor.Position = location;
MouseClick1();
}
else
{
//Starta något som uppdaterar igen tex//
}
return;
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabeld = true;
}
//Stop knapp
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabeld = false;
}
Annons