Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

A few useful methods to make a bot in VB

A few useful methods to make a bot in VB

I thought some might be interested by VB because it's a pretty intuitive coding language so here are some cool stuff to make bots ;

Detecting a pixel color :

Code
'Taking a screenshot and converting to Graphics type, note that here the screen resolution is 1280x720.
        Dim Img As New Bitmap(1280, 720)
        Dim ImgGraphics As Graphics = Graphics.FromImage(Img)
        ImgGraphics.CopyFromScreen(0, 0, 0, 0, Img.Size)

'Getting the pixel color at (X,Y) on the screenshot, note that i'm using .ToArgb to compare a color value, change -65906 to the color you want.
        Dim Slot1Selec As Color = Img.GetPixel(X, Y)
        If Slot1Selec.ToArgb = -65906 Then
           'Do something here
        End If

'Getting rid of the BMP and Graphics screenshots, else it will constantly increase your ram usage
        Img.Dispose()
        ImgGraphics.Dispose()

Simulating mouse clicks and keyboard inputs :

You have to declare those functions/sub right after your Public Class line ;

Code
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Short
Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long) 'Long may have to change to type Int32 or DWORD
    'LEFTDOWN = &H2
    'LEFTUP = &H4
    'RIGHTDOWN = &H8
    'RIGHTUP = &H10
    'MIDDLEUP = &H40
    'MIDDLEDOWN = &H20
Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Left means left click, right means, alright you got it.
DOWN is when a click button is pressed, UP is when its released.

Changing the mouse (X,Y) coordinates and simulating a mouse click :

Code
Cursor.Position = New Point(X, Y)
                mouse_event(&H2, 0, 0, 1, 0)
                mouse_event(&H4, 0, 0, 1, 0)

Simulating a key press :

Quote:SendKeys.Send("{Enter}")

I'm not allowed to post any outside links, but you can find all the key values by typing 'SendKeys Statement' on Google.

You can also send a complete line of text directly from a textbox, and/or add some raw text :

Code
SendKeys.Send((TextBox1.Text) & "Some text you want to add after the text from Textbox1.text")

Opening a link in the default browser :

Code
Process.Start("link")

Hoping this will be useful to some users.
I can also help you on skype in visual basic if you are a begginer, my skype is : turgodi
Best regards.
I been trying to come up with a better method than getpixel, but everything I try doesn't work out. I made a bot that works just like this, but a lot more user friendly for the kids who use it.
(Aug 29, 2015 07:29 AM)Jackie Chun Wrote:  I been trying to come up with a better method than getpixel, but everything I try doesn't work out. I made a bot that works just like this, but a lot more user friendly for the kids who use it.

Me too, i'm glad someone had the same problem.
It's the only thing that worked out for me, but i'm pretty sure someone good in visual basic will have other methods.
(Aug 29, 2015 07:38 AM)Minerz Wrote:  Me too, i'm glad someone had the same problem.
It's the only thing that worked out for me, but i'm pretty sure someone good in visual basic will have other methods.

I'm still storing my image data in a picturebox. Mainly because my new method wouldn't work and because I haven't felt like programmatically handling the bitmaps for each line of bot script.

IF you want I could show you my bot source, It's became quite the popular bot in the past year or so. At first I thought this thread was c/p from my source but it obviously wasnt :P
Use this for when you get an image, it's much faster, and efficient.
[Image: wbgZ06Q.png]
Well each bot have its purpose.
In my case it was to detect selected items in a game to automate trades.

Thank you for your advices kemwelly.
Better functions but in c# :

Code
public static void Text(string TXT, int windowhandle)
{
    for (int i = 0; i < TXT.Length; i++)
    {
      SendMessage(windowhandle, 0x0102, (int)Convert.ToInt32(TXT[i]), 0);
      System.Threading.Thread.Sleep(15);
    }

}
public static void SendKey(int Key, int windowhandle)
{
    SendMessage(windowhandle, 0x0100, Key, 0);
    System.Threading.Thread.Sleep(20);
    SendMessage(windowhandle.Pid, 0x0101, Key, 0);
}

public static void SendKeyDown(int Key, int windowhandle)
{
    SendMessage(windowhandle, 0x0100, Key, 0);
    System.Threading.Thread.Sleep(15);

}
public static void SendUp(int Key, int windowhandle)
{
    SendMessage(windowhandle, 0x0101, Key, 0);
    System.Threading.Thread.Sleep(15);

}
public static void Click(int xpos, int ypos, string button, int windowhandle)
{
    var pos = MakeLParam(xpos, ypos);
    switch (button)
    {
      case "left":
      SendMessage(windowhandle, 0x0200, 0, pos);
      SendMessage(windowhandle, 0x201, 0x0001, pos);
      SendMessage(windowhandle, 0x202, 0x0001, pos);
      break;
      case "right":
      SendMessage(windowhandle, 0x0200, 0, pos);
      SendMessage(windowhandle, 0x204, 0x0002, pos);
      SendMessage(windowhandle, 0x205, 0x0002, pos);
      break;
    }
}
public static void Move(int xpos, int ypos, int windowhandle)
{
    var pos = MakeLParam(xpos, ypos);
    SendMessage(windowhandle, 0x0200, 0, pos);
    SendMessage(windowhandle, 0x02A1, 0x0001, pos);
}
public static void SurvolDown(int xpos, int ypos, windowhandle)
{
    var pos = MakeLParam(xpos, ypos);
    SendMessage(windowhandle, 0x0200, 0, pos);
    global.Sleep(15);
    SendMessage(windowhandle, 0x02A1, 0x0001, pos);
    SendMessage(windowhandle, 0x201, 0x0001, pos);
    SendMessage(windowhandle, 0x201, 0x0001, pos);
}
public static void SurvolUp(gint windowhandle)
{
    var pos = MakeLParam(10, 10);
    SendMessage(windowhandle, 0x202, 0x0001, pos);
}
static int MakeLParam(int LoWord, int HiWord)
{
    return ((HiWord << 16) | (LoWord & 0xffff));
}
You could also do a lot of botting through httpwebrequest and a web browser, so maybe you should add it to this tutorial. Good work though, thanks for the share.
very helpful, thanks. can you help me though? i basically just need the mouse x,y to go when pixel is detected to that point and click it..
Buying BTC for PP, PM me for exchange! @ 10%
(Aug 30, 2015 06:21 AM)Lexxi. Wrote:  very helpful, thanks. can you help me though? i basically just need the mouse x,y to go when pixel is detected to that point and click it..

Here, try that, please note that i'm using a timer named Timer1 Enabled :
(make sure to change 1280, 720 by your screen resolution)

Code
Public Class FiBot
    Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

    Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long) 'Long may have to change to type Int32 or DWORD
    'LEFTDOWN = &H2
    'LEFTUP = &H4
    'RIGHTDOWN = &H8
    'RIGHTUP = &H10
    'MIDDLEUP = &H40
    'MIDDLEDOWN = &H20

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles RefreshTimer.Tick

' Creating a screenshot as bmp
      Dim Img As New Bitmap(1280, 720)
      Dim ImgGraphics As Graphics = Graphics.FromImage(Img)
      ImgGraphics.CopyFromScreen(0, 0, 0, 0, Img.Size)

'  Checking the pixel color, if the color is the one you want the mouse will move to this position and click
Dim Pixel As Color = Img.GetPixel(x, y)
      If Pixel.ToArgb = colorchosen
      Cursor.Position = New Point(x, y)
      mouse_event(&H2, 0, 0, 1, 0)
      mouse_event(&H4, 0, 0, 1, 0)
      End If

' Getting rid of the .bmp
      Img.Dispose()
      ImgGraphics.Dispose()
    End Sub
End Class

So you might ask me how do i get the Argb value of the color you want, here's a quick code to get the pixel color under your mouse and it's .ToArgb value :
(you will also need a timer which is enabled, in my case its name is RefreshTimer)

Code
Public Class FiBot
    Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

    Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long) 'Long may have to change to type Int32 or DWORD
    'LEFTDOWN = &H2
    'LEFTUP = &H4
    'RIGHTDOWN = &H8
    'RIGHTUP = &H10
    'MIDDLEUP = &H40
    'MIDDLEDOWN = &H20

    Private Sub RefreshTimer_Tick(sender As Object, e As EventArgs) Handles RefreshTimer.Tick
      ' Creating a screenshot as bmp
      Dim Img As New Bitmap(1920, 1080)
      Dim ImgGraphics As Graphics = Graphics.FromImage(Img)
      ImgGraphics.CopyFromScreen(0, 0, 0, 0, Img.Size)

      ' Checking the pixel color
      Dim PixelUnderMouse As Color = Img.GetPixel(MousePosition.X, MousePosition.Y)
      ' Writing the .ToArgb value somewhere, here in a textbox named Textbox2
      TextBox2.Text = PixelUnderMouse.ToArgb

      ' Getting rid of the .bmp
      Img.Dispose()
      ImgGraphics.Dispose()
    End Sub
End Class

Here's an other quick code to get the Mouse position (X and Y) :
(Again, you will need a timer, here named Timer by default, and it must be enabled. Change the interval in ms to a smaller number to make it more accurate)

Code
Public Class FiBot
    Private Sub Timer_Tick(sender As Object, e As EventArgs) Handles Timer.Tick
      ' Getting mouse positions X and Y and writing them in one label
      Label1.Text = ("X: " & MousePosition.X & "Y : " & MousePosition.Y)
    End Sub
End Class


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by z1995zFeb 12, 2016 04:13 PM 5 288 Feb 12, 2016 04:13 PM
Last Post: z1995z