Question My first application (loop problem & hint for next feature needed)

liuzewei

New member
Joined
Oct 16, 2011
Messages
1
Programming Experience
Beginner
hello community!
i am new to VB and i try to create my first application to automate some clicks on a facebook game.
(sorry for my bad english, my last lesson in school was in 1995)


My first problem is a loop: I created a recorder function, but if i activate my loop it loops endless (should take the number of loops from textbox)
If i add a messagebox it works, but if i add PlayTimer.Start() its endless
... anybody can help me ???

VB.NET:
    Dim result As Integer
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Short
    Dim curclicks = 0
    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)
    Private Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move
    Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
    Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
    Private Const MOUSEEVENTF_MOVE = &H1 ' mouse move
    Private Const MOUSEEVENTF_MIDDLEDOWN = &H20
    Private Const MOUSEEVENTF_MIDDLEUP = &H40
    Private Const MOUSEEVENTF_RIGHTDOWN = &H8
    Private Const MOUSEEVENTF_RIGHTUP = &H10
    Private 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)
    Private Const mouseclickup = 4
    Private Const mouseclickdown = 2




#End Region
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RecorderTimer.Tick
        Dim Mouse As Point = Control.MousePosition
        If GetAsyncKeyState(MOUSEEVENTF_LEFTDOWN) Then
            ListBox2.Items.Add("Left")
            ListBox3.Items.Add("Right")
        ElseIf GetAsyncKeyState(MOUSEEVENTF_RIGHTDOWN) Then
            ListBox2.Items.Add("Right")
            ListBox3.Items.Add("Right")
        Else
            ListBox2.Items.Add(Mouse.X)
            ListBox3.Items.Add(Mouse.Y)
        End If
        ListBox1.Items.Add(GetAsyncKeyState(1))
    End Sub




    Private Sub delay(ByVal zeit As Integer)
        Dim zeit1 As Integer = System.Environment.TickCount
        While (System.Environment.TickCount - zeit1) < zeit
            Application.DoEvents()
        End While
    End Sub




    Private Sub looper()
        Dim schleife As Integer = CInt(TextBox2.Text)
        If CheckBox1.Checked = True Then
            For i As Integer = 1 To schleife
                If i <= schleife Then
                    restart()
                ElseIf i > schleife Then
                    MsgBox("Done !   ... max loops reached")
                End If
            Next i
        ElseIf CheckBox1.Checked = False Then
            MsgBox("Done !  ... no loop activated")
        End If
    End Sub






    Private Sub restart()
        Dim pause As Integer = CInt(TextBox1.Text)
        ListBox2.SelectedIndex = 0
        ListBox3.SelectedIndex = 0
        delay(pause)
        PlayTimer.Start()
    End Sub










    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlayTimer.Tick
        If ListBox1.Text = "-32767" Or ListBox1.Text = "-32768" Then
            mouse_event(mouseclickdown, 0, 0, 0, 0)
            mouse_event(mouseclickup, 0, 0, 0, 0)
        End If
        If ListBox3.Text = "Left" Then
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
        ElseIf ListBox3.Text = "Right" Then
            mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)
        ElseIf Not ListBox3.Text = "Left" And Not ListBox3.Text = "Right" Then
            Cursor.Position = New Point(ListBox2.Text, ListBox3.Text)
        End If
        Try
            ListBox1.SelectedIndex = ListBox2.SelectedIndex + +1
            ListBox2.SelectedIndex = ListBox2.SelectedIndex + +1
            ListBox3.SelectedIndex = ListBox3.SelectedIndex + +1


        Catch ex As Exception
            PlayTimer.Stop()
            looper()


        End Try
    End Sub




The 2nd question i got: Can anybody give me some code / links / tutorial how to handle the next function i am planning?
... i will try to explain it (look at the attachment picture):

Because of different monitor resolutions i need a function that maybe draw a square to boarder the gameplay area, then record some coordinates that can be played by clicking on a button.
(visit neighbor, reload game, visit next neighbor, ...)

I dont know how to start this or what i need to search for to find some tutorials, maybe someone can give me a hint ?!
 

Attachments

  • project.jpg
    project.jpg
    341 KB · Views: 29
G'd Morning liuzewei,
I guess your loop is endless because everytime a page refresh it doesn't keep it's value. I would start to store the value in a session variable. Or may be you can use some javascript code.
For the second question: There are several ways to do it. The easier i know (i'm not a web programmer so i go for the techniques accordingly to my knowledge) is using two divs. The first one will adjust itseflt to the width and Height of the available area. Something like this: width:100% and height:80%.
Then the second div, placed inside in a relative position to the first one. This will be holding your content. To keep it "fixed" let the left and right margins in auto mode and the width and height fixed to the size you need to display the content. It may look like this:
VB.NET:
 <div id="divMenu" style="width: 300px; margin-left: auto; margin-right: auto; position: relative; height: 400px; top: 0px;">

G'd luck
 
Back
Top