Our members are dedicated to PASSION and PURPOSE without drama!

[VB.NET] Clicker

Started by VLS, November 26, 2012, 04:10:50 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

VLS

In order to create your clicker in VB.NET you must do the following:

1) Get the handle of the target (casino) window.
2) Create a RECT structure with the coordinates.
3) Move the mouse to the coordinates within the casino window.
4) Perform the actual click operation.

Let's go at it step by step.




NOTE: since we'll use external DLL imports, you must add the line:

Code (vbnet) Select
Imports System.Runtime.InteropServices

To the very top of your VB.NET file.




1) Get the handle of the target (casino) window:

In order to get the handle of the casino window you must use a function that returns this handle based on either the process id OR the window's title. We will use a title-based one, in our case: findWindow.

The declaration is this:
Code (vb.net) Select

<System.Runtime.InteropServices.DllImport("user32.dll")> _
Private Shared Function FindWindow( _
    ByVal lpClassName As String, _
    ByVal lpWindowName As String) As System.IntPtr
End Function


Now we must get the handle into a variable of type intPtr

Code (vbnet) Select
Dim casinoHwnd As IntPtr
casinoHwnd = FindWindow(vbNullString, "Exact casino window title here")


vbNullString means you don't pass the class name of the casino and are only using the title.




2) Create a RECT structure with the coordinates.

First create your RECT structure:

Code (vbnet) Select

'RECT structure
    Structure RECT
        Public Left As Integer
        Public Top As Integer
        Public Right As Integer
        Public Bottom As Integer
    End Structure


Now set a variable with it, passing the casino handle (casinoHwnd) to the GetWindowRect() function.

Code (vbnet) Select

<System.Runtime.InteropServices.DllImport("user32")> _
    Private Shared Function GetWindowRect(ByVal hwnd As IntPtr, ByRef lpRect As Rectangle) As IntPtr
    End Function


And set a variable with it:

Code (vbnet) Select
        Dim stRect As RECT
        GetWindowRect(casinoHwnd, stRect)


We are halfway there!




3) Move the mouse to the coordinates within the casino window.

In order to move the mouse you have to use the  SetCursorPos(x, y) function.

It is declared like this:
Code (vbnet) Select

Public Declare Function SetCursorPos Lib "user32" (ByVal X As Integer, ByVal why As Integer) As Integer


And you simply use the coordinates of the number to click + the coordinates of the casino window, like this:

Let's suppose the #1 is at coordinates x:188, y:352 in the casino window.

In order to move the cursor there you use the .left and .top propierties of the stRect structure and add the coordinates:
Code (vbnet) Select

SetCursorPos(stRect.Left + 188, strRect.Top + 352)


And the cursor is right there focused on the exact number.




4) Perform the actual click operation.

In order to perform the actual click, we must invoke the mouse_event function.

It is declared like this, including the two constants for the down/up event combo to recreate the click:

Code (vbnet) Select

Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)

    Public Const MOUSEEVENTF_LEFTDOWN = &H2
    Public Const MOUSEEVENTF_LEFTUP = &H4


And now simply use:

Code (vbnet) Select

        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)



Voilá

YOU JUST DID YOUR CLICKER MODULE IN VISUAL BASIC.NET!

Victor
Email/Paypal: betselectiongmail.com
-- Victor

Ralph

At Steve's forum it was the start for the bot. A bot I did, before but could of course not go further without a way to know the cords, so we always start here.


The cords are different, do you want the screen or the form?  The clicker should capture the pixel color as well, as it is often wanted.


It can be used so it stores it, can work as clicker, but can as well make users in a position they think it is not working. Best is to use the forms coordinates.


You can fix it from global using  calculating the  "left" and "top" from the global from the form window, and if not margin is zero take it in, then it works even for a window which is moved.. The API way is normally to get the global coordinates, which can click outside the program form or windows


Abc123

Hi,
I am a newbie, and want learn to program a simple bot/clicker.

Could somebody tell me where I can find more information?

Thanks in advance.


Abc123

VLS

Quote from: Abc123 on December 08, 2013, 02:38:19 PMCould somebody tell me where I can find more information?

Good and bad news here.

a) Availability of information depends on what programming language you are aiming to use.

b) There are no "official" tutorials on bot making per se. Every programmer usually makes his own ways using the information for the "building parts" that compound the bot (i.e. there's a plethora of image recognition info and whitepapers, a plethora of raw WIN32 API programming sites including MSDN -invaluable!-, a plethora of separated tutorials published in different for each language -C/VB/Delphi/Etc).




There's a project for an easy-to-extend public-domain bot at: BetSoftware
Email/Paypal: betselectiongmail.com
-- Victor

Abc123

Hi Victor,

Great....can't wait!


Thanks,


Abc123