AB
Active Member
Here are some of my autoing functions and procedures. There is an explanation on how to use them included with the source.
These functions and procedures are for your learning/use | Please give credit.
These functions and procedures are for your learning/use | Please give credit.
Mouse
Public Function mousePos() As System.Drawing.PointUsage: msgBox('This is the mouse position: ' & mousePos.tostring)
Explanation: Returns the mouse position as a system.drawing.point.
Parameters: None
Code:
Public Function mousePos() As System.Drawing.Point
mousePos = Windows.Forms.Cursor.Position()
End Function
Public Sub moveMouse(ByVal x As Integer, ByVal y As Integer)
Usage: moveMouse(100,100)
Explanation: Sets the mouse position to x,y
Parameters: x - X postition on the screen; y - Y position on the screen
Code:
Public Sub moveMouse(ByVal x As Integer, ByVal y As Integer)
Windows.Forms.Cursor.Position = New Point(x, y)
End Sub
Public Sub moveMouseSmooth(ByVal x As Integer, ByVal Y As Integer, ByVal steps As Integer)
Usage: moveMouseSmooth(100,100,300)
Explanation: Moves the mouse to the position x,y,like a human would. < steps = smoother
Parameters: x - X postition on the screen; y - Y position on the screen; steps - number of times the cursor will "jump" in a line
Code:
Public Sub moveMouseSmooth(ByVal x As Integer, ByVal Y As Integer, ByVal steps As Integer)
Dim diffX As Integer
Dim diffY As Integer
Dim I As Integer
If mousePos.X > x Then
diffX = mousePos.X - x
Else : diffX = x - mousePos.X
End If
If mousePos.Y > Y Then
diffY = mousePos.Y - Y
Else : diffY = Y - mousePos.Y
End If
diffX = diffX / steps
diffY = diffY / steps
For I = 1 To steps
If mousePos.X > x Then
moveMouse(mousePos.X - diffX, mousePos.Y)
Else : moveMouse(mousePos.X + diffX, mousePos.Y)
End If
If mousePos.Y > Y Then
moveMouse(mousePos.X, mousePos.Y - diffY)
Else : moveMouse(mousePos.X, mousePos.Y + diffY)
End If
wait(1)
Next
End Sub
Public Sub clickMouse(ByVal x As Integer, ByVal y As Integer, ByVal left As Boolean)
Usage: clickMouse(100,100,true)
Explanation: Clicks the mouse at the postition x,y
Parameters: x - X postition on the screen; y - Y position on the screen; left - true = left click | false = right click
Code:
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Int32, ByVal dx As Int32, ByVal dy As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As Int32)
Public Sub clickMouse(ByVal x As Integer, ByVal y As Integer, ByVal left As Boolean)
moveMouse(x, y)
If left Then
mouse_event(&H2, 0, 0, 0, 0)
mouse_event(&H4, 0, 0, 0, 0)
Else
mouse_event(&H8, 0, 0, 0, 0)
mouse_event(&H10, 0, 0, 0, 0)
End If
End Sub
Public Sub clickMouseEx(ByVal x As Integer, ByVal y As Integer, ByVal randomX As Integer, ByVal randomY As Integer, ByVal waitTime As Integer, ByVal randomWaitTime As Integer, ByVal left As Boolean)
Usage: clickMouseEx(100,100,3,3,20,30,true)
Explanation: Clicks the mouse at the postition x,y like a human.
Parameters: x - X postition on the screen; y - Y position on the screen; randomX - ammount of pixels to randomly add to "x"; randomY - ammount of pixels to randomly add to "y"; waitTime - how long to wait to between moving the mouse and clicking the mouse in ms; randomWaitTime - randomly adds to "waitTime" in ms; left - true = left click | false = right click
Code:
Public Sub clickMouseEx(ByVal x As Integer, ByVal y As Integer, ByVal randomX As Integer, ByVal randomY As Integer, ByVal waitTime As Integer, ByVal randomWaitTime As Integer, ByVal left As Boolean)
moveMouseSmooth(x + Rnd(randomX), y + Rnd(y))
wait(waitTime + Rnd(randomWaitTime))
clickMouse(mousePos.X, mousePos.Y, left)
End Sub
Bitmaps
Private Function getBitmap(ByVal area As Rectangle) As BitmapUsage: dim bmp as new bitmap(100,100) = getBitmap(new rectangle(1,1,100,100))
Explanation: Copies the selected screen section (area) and returns it.
Parameters: area - the selected screen section to be copied.
Code:
Private Function getBitmap(ByVal area As Rectangle) As Bitmap
Dim areasize As Size = area.Size
Dim tempBitmap As New Bitmap(areasize.Width, areasize.Height)
Graphics.FromImage(tempBitmap).CopyFromScreen(area.Location, New Point(), areasize)
Return tempBitmap
End Function
Private Function findBitmapIn(ByRef x As Integer, ByRef Y As Integer, ByVal targetBitmap As Bitmap, ByVal zone As Rectangle) As Boolean
Usage: if findBitmapIn(x,y,bmp,new rectangle(1,1,100,100)) then
Explanation: Searches the screen for "targetBitmap", if found the returns true.
Parameters: x - Your variable that the position of the found bitmap will return; y - Your variable that the position of the found bitmap will return; targetBitmap - The bitmap that will be searched for; zone - The area that will be scanned.
Code:
Private Function findBitmapIn(ByRef x As Integer, ByRef Y As Integer, ByVal targetBitmap As Bitmap, ByVal zone As Rectangle) As Boolean
Dim areaSize As Size = zone.Size
Dim tempBitmap As New Bitmap(areaSize.Width, areaSize.Height)
Graphics.FromImage(tempBitmap).CopyFromScreen(zone.Location, New Point(), areaSize)
Dim targerColor As System.Drawing.Color = targetBitmap.GetPixel(1, 1)
For scanX = 1 To (tempBitmap.Width - targetBitmap.Height)
For scanY = 1 To (tempBitmap.Height - targetBitmap.Height)
If tempBitmap.GetPixel(scanX, scanY) = targerColor Then
Dim targetSize As Size = targetBitmap.Size
Graphics.FromImage(tempBitmap).CopyFromScreen(New Point(scanX, scanY), New Point(), targetSize)
For scanX2 As Integer = 1 To targetBitmap.Width - 1
For scanY2 As Integer = 1 To targetBitmap.Height - 1
If Not targetBitmap.GetPixel(x, Y) = tempBitmap.GetPixel(x, Y) Then
Return False
Exit Function
End If
Next : Next
End If
Next : Next
Return False
End Function
Colors
Function getColor(ByVal x As Integer, ByVal y As Integer) As IntegerUsage: dim myColor as integer = getColor(100,100)
Explanation: Will return the color of the pixel at x,y.
Parameters: x - the X position of the pixel; y - the Y position of the pixel.
Code:
Function getColor(ByVal x As Integer, ByVal y As Integer) As Integer
Dim areasize As Size = New Rectangle(x, y, 1, 1).Size
Dim tempBitmap As New Bitmap(areasize.Width, areasize.Height)
Graphics.FromImage(tempBitmap).CopyFromScreen(New Rectangle(x, y, 1, 1).Location, New Point(), areasize)
Dim tempColor As System.Drawing.Color = tempBitmap.GetPixel(x, y)
Return Color.FromArgb(255, tempColor.R, tempColor.G, tempColor.B).GetHashCode()
End Function
Function findcolor(ByRef x As Integer, ByRef y As Integer, ByVal TargetColor As Integer, ByVal area As Rectangle) As Boolean
Usage: if findColor(x,y,myColor,new rectangle(1,1,100,100)
Explanation: Will scan for "TargetColor" on the screen, if found the will return true.
Parameters: x - Your variable that the position of the found color will return; y - Your variable that the position of the found color will return; TargetColor- The color that will be searched for; area - The area that will be scanned.
Code:
Function findcolor(ByRef x As Integer, ByRef y As Integer, ByVal TargetColor As Integer, ByVal area As Rectangle) As Boolean
Dim areasize As Size = area.Size
Dim tempBitmap As New Bitmap(areasize.Width, areasize.Height)
Graphics.FromImage(tempBitmap).CopyFromScreen(area.Location, New Point(), areasize)
Dim tempColor As System.Drawing.Color
Dim convertedColor As Integer
For scanX = 1 To area.Width - 1
For scanY = 1 To area.Height - 1
tempColor = tempBitmap.GetPixel(x, y)
convertedColor = Color.FromArgb(255, tempColor.R, tempColor.G, tempColor.B).GetHashCode()
If (convertedColor = TargetColor) Then
Return True
Exit Function
End If
Next : Next
Return False
End Function
Please Comment!
- AB

