SRL Archive - C#/Visual Basic Help and Tutorials

[VB] Mouse Events Module


Frederick

2008-04-21 12:19:17

This module of course comes in great use when your wanting to move your mouse to positions on your screen, Also at the bottom will be examples of how i've used it.

So, The Module Itself:

Option Explicit
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Declare Function GetKeyPress Lib "user32" Alias "GetAsyncKeyState" (ByVal key As Long) As Integer
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal Y As Long) As Long

Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_MIDDLEDOWN = &H20
Public Const MOUSEEVENTF_MIDDLEUP = &H40
Public Const MOUSEEVENTF_RIGHTDOWN = &H8
Public Const MOUSEEVENTF_RIGHTUP = &H10
Public Const MOUSEEVENTF_MOVE = &H1

Public Type POINTAPI
x As Long
Y As Long
End Type
Public Random As Integer
Public Log As Integer


Public Function GetCurrentX() As Long
Dim Position As POINTAPI
GetCursorPos Position
GetCurrentX = Position.x
End Function

Public Function GetCurrentY() As Long
Dim Position As POINTAPI
GetCursorPos Position
GetCurrentY = Position.Y
End Function

Public Sub LeftClick()
LeftDown
Sleep(Random)
LeftUp
End Sub

Public Sub LeftDown()
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
End Sub

Public Sub LeftUp()
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub

Public Sub MiddleClick()
MiddleDown
MiddleUp
End Sub

Public Sub MiddleDown()
mouse_event MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0
End Sub

Public Sub MiddleUp()
mouse_event MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0
End Sub

Public Sub MoveMouse(xMove As Long, yMove As Long)
mouse_event MOUSEEVENTF_MOVE, xMove, yMove, 0, 0
End Sub

Public Sub RightClick()
RightDown
Sleep(Random)
RightUp
End Sub

Public Sub RightDown()
mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
End Sub

Public Sub RightUp()
mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
End Sub

Some examples of use:

Public Sub Drop()
'FIRST ROW
'First item

Call SetCursorPos(Int(Rnd * 2 + 835), Int(Rnd * 2 + 395))
Call Sleep(Random)
Call RightClick
Call Sleep(Random)
Call SetCursorPos(Int(Rnd * 2 + 821), Int(Rnd * 2 + 435))
Call Sleep(Random)
Call LeftClick
Call Sleep(Random)

end sub

//This shows the basics of using the module, The Rnd is a random ammount this trys to stop it being so suspicous - but still be verry careful

but also:


lblCurrent.Caption = "X Cordinates: " & GetCurrentX & " Y Cordinates: " & GetCurrentY

//This will show the current mouse X and Y Cordinates into a label called lblCurrent.

–

Hope this helps.

– Fred

JuKKa

2008-04-21 12:46:08

Is sleep the same as Wait? if yes u should add one between the mouse clicks.

(down wait up)

Frederick

2008-04-21 12:59:48

From: JuKKa
Is sleep the same as Wait? if yes u should add one between the mouse clicks.

(down wait up)


lol good point,

updated the code

JuKKa

2008-04-21 14:06:05

is "random" a variable?

I would love if u could add some FindColor functions. And maybe explain them a bit. Never really got into visual basic bots but i might now

Frederick

2008-04-21 14:55:33

Yeah its a variable,

+ all the above code is from the module

i call most of it from the main form:


If GetKeyPress(vbKeyShift) Then 'If the key shift is pressed then:
Call Drop 'calls the drop function
End If 'ends the if statement
Random = Int(Rnd * 300 + 150) 'sets the random variable to a random number

//Edit - The only problem with VB Bots is people not trusted the application as keyloggers etc can be put inside.

+ i have an aimbot from back in the day for blackhawk down that used findcolours ill dig it up later on

Lalaji

2008-04-23 21:44:47

This WILL come in handy…I been wondering how to take control of the mouse, lol

Ty for posting

R0b0t1

2008-05-10 17:30:18

Call is legacy coding, you shouldn't really use it anymore.

Zigon

2008-06-09 17:57:46

I haven't used scar or played runescape in the loongest time (since kaitnieks forums). Are there vb bots now?