Need help with Program

Discussion in 'Programming General' started by bloodbaron20, Jan 20, 2009.

Need help with Program
  1. Unread #1 - Jan 20, 2009 at 1:18 PM
  2. bloodbaron20
    Joined:
    Mar 6, 2008
    Posts:
    8
    Referrals:
    0
    Sythe Gold:
    0

    bloodbaron20 Newcomer

    Need help with Program

    Hello all,
    this is my first post.

    I have some problems with my little vb6 program,
    I hope someone can help me with it :)

    Download it here

    This is my Form:
    [​IMG]

    the form code:
    Code:
    Dim MyPointAPI As POINTAPI
    Private Type POINTAPI
      x As Long
      y As Long
    End Type
    
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    
    Private Sub B2uit_Click()
    Move2.Enabled = True
    Mouse2.Enabled = True
    B2uit.Visible = False
    B2aan.Visible = True
    End Sub
    
    Private Sub B2aan_Click()
    Move2.Enabled = False
    Mouse2.Enabled = False
    B2uit.Visible = True
    B2aan.Visible = False
    End Sub
    
    Private Sub B3uit_Click()
    Move3.Enabled = True
    Mouse3.Enabled = True
    B3uit.Visible = False
    B3aan.Visible = True
    End Sub
    Private Sub B3aan_Click()
    Move3.Enabled = False
    Mouse3.Enabled = False
    B3uit.Visible = True
    B3aan.Visible = False
    End Sub
    
    Private Sub B4aan_Click()
    Move4.Enabled = False
    Mouse4.Enabled = False
    B4uit.Visible = True
    B4aan.Visible = False
    End Sub
    Private Sub B4uit_Click()
    Move4.Enabled = True
    Mouse4.Enabled = True
    B4uit.Visible = False
    B4aan.Visible = True
    End Sub
    
    Private Sub Command1_Click()
    If Mouse1.Text = "Links klik" Then
    LeftClick1 Move1
    End If
    End Sub
    
    Private Sub Command2_Click()
    Unload Me
    End Sub
    
    Private Sub Form_Load()
    Timer1.Enabled = True
    Timer2.Enabled = True
    Move2.Enabled = False
    Mouse2.Enabled = False
    B2aan.Visible = False
    B2uit.Visible = True
    Move3.Enabled = False
    Mouse3.Enabled = False
    B3aan.Visible = False
    B3uit.Visible = True
    Move4.Enabled = False
    Mouse4.Enabled = False
    B4aan.Visible = False
    B4uit.Enabled = True
    End Sub
    Public Sub Timer1_Timer()
      l = GetCursorPos(MyPointAPI)
      Label1.Caption = "Positie: " & CStr(MyPointAPI.x) & ", " & CStr(MyPointAPI.y)
    End Sub
    
    Private Sub Timer2_Timer()
    Dokeys
    End Sub
    
    and the Module:
    Code:
    Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey 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)
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds 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 Function LeftClick1(ByVal x As Long, ByVal y As Long)
        SetCursorPos x, y
        mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
        Sleep 50
        mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
    End Function
    Public Function GetX() As Long
        Dim n As POINTAPI
        GetCursorPos n
        GetX = n.x
    End Function
    
    ' Function to get mouse y-position
    Public Function GetY() As Long
        Dim n As POINTAPI
        GetCursorPos n
        GetY = n.y
    End Function
    
    ' Sub to emulate left button click (down + up)
    Public Sub LeftClick()
        LeftDown
        LeftUp
    End Sub
    
    ' Sub to emulate left button down
    Public Sub LeftDown()
        mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
    End Sub
    
    ' Sub to emulate left button up
    Public Sub LeftUp()
        mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
    End Sub
    
    ' Sub to emulate middle button click (down + up)
    Public Sub MiddleClick()
        MiddleDown
        MiddleUp
    End Sub
    
    ' Sub to emulate middle button down
    Public Sub MiddleDown()
        mouse_event MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0
    End Sub
    
    ' Sub to emulate middle button up
    Public Sub MiddleUp()
        mouse_event MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0
    End Sub
    
    ' Sub to emulate right button click (down + up)
    Public Sub RightClick()
        RightDown
        RightUp
    End Sub
    
    ' Sub to emulate right button down
    Public Sub RightDown()
        mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
    End Sub
    
    ' Sub to emulate right button up
    Public Sub RightUp()
        mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
    End Sub
    
    ' Sub to move mouse position with x,y
    Public Sub MoveMouse(xMove As Long, yMove As Long)
        mouse_event MOUSEEVENTF_MOVE, xMove, yMove, 0, 0
    End Sub
    
    ' Sub to set mouse position to x,y
    Public Sub SetMousePos(xPos As Long, yPos As Long)
        SetCursorPos xPos, yPos
    End Sub
    
    
    
    Public Sub Dokeys()
        If GetAsyncKeyState(vbKeyF7) Then
            MsgBox "Programma Gestart.", vbInformation, "Yay"
        
            End If
    End Sub
    
    
    (Sorry that the program is in dutch..)

    I want when I typ in the coordinates and select from the combo box leftclick, rightclick or movemouse and press start the mouse is going to the coordinates and leftclicks, rightclicks or just moves to there..
    I hope u know what i mean..

    (sorry for my bad english.. i'm dutch >_< )
    is the awnser so easy that nobody wants to tell me? 27 viewers and no comments =/
     
  3. Unread #2 - Jan 21, 2009 at 10:46 PM
  4. Darthatron
    Joined:
    May 22, 2006
    Posts:
    1,612
    Referrals:
    3
    Sythe Gold:
    0

    Darthatron Massive Troll
    Retired Sectional Moderator Visual Basic Programmers

    Need help with Program

    Hello. If you could upload your project and PM it to me, I'll be able to hope. :)
     
  5. Unread #3 - Jan 22, 2009 at 3:02 AM
  6. bloodbaron20
    Joined:
    Mar 6, 2008
    Posts:
    8
    Referrals:
    0
    Sythe Gold:
    0

    bloodbaron20 Newcomer

    Need help with Program

    thanks =] ill upload it ;)
     
  7. Unread #4 - Jan 25, 2009 at 12:14 AM
  8. Darthatron
    Joined:
    May 22, 2006
    Posts:
    1,612
    Referrals:
    3
    Sythe Gold:
    0

    Darthatron Massive Troll
    Retired Sectional Moderator Visual Basic Programmers

    Need help with Program

    Sorry, I forgot about this. The problem was that you were using a string as your position for the mouse to go.

    So, when you were calling 'SetCursorPos', it looked a little something like this:
    Code:
    SetCursorPos "30, 780", 0
    This was confusing Visual Basic, and is what caused the error.

    So anyway, this is the fix...

    Replace...
    Code:
    Private Sub Command1_Click()
    If Mouse1.Text = "Links klik" Then
    LeftClick1 Move1
    End If
    End Sub
    
    With...
    Code:
    Private Sub Command1_Click()
        If Mouse1.Text = "Links klik" Then
            LeftClick1 CLng(Trim$(Split(Move1.Text, ",")(0))), CLng(Trim$(Split(Move1.Text, ",")(1)))
        End If
    End Sub
    That fixes the problem, by 'splitting' the string into 2 parts. (The left and right side of the ",")

    Also: Don't just use 'TextBox' if you want to get the Text in it. Always use 'TextBox.Text'. Same goes with Labels (Captions), and anything with a value. It just makes your code a slight bit faster. :)
     
  9. Unread #5 - Jan 25, 2009 at 12:19 PM
  10. bloodbaron20
    Joined:
    Mar 6, 2008
    Posts:
    8
    Referrals:
    0
    Sythe Gold:
    0

    bloodbaron20 Newcomer

    Need help with Program

    yes! thnx man ;)
     
< I cant uninstall Java!! I cant play runescape!! | [Help] Grab usernames from multiline textbox >

Users viewing this thread
1 guest


 
 
Adblock breaks this site