Mouse Click and Mouse Move.

Discussion in 'Programming General' started by -Ken-, Aug 28, 2008.

Mouse Click and Mouse Move.
  1. Unread #1 - Aug 28, 2008 at 7:22 PM
  2. -Ken-
    Referrals:
    0

    -Ken- Guest

    Mouse Click and Mouse Move.

    Hello.

    I'm having trouble with 2 commands.

    I need to know how to get the mouse to move from one place... To another in a visual basic program... Say you click a button then the mouse moves to that place.

    Also I need to know how to get the mouse to click somewhere, say a code like this "mouse.click 007 800" (007 800 would be coordinates).

    Good day
     
  3. Unread #2 - Aug 28, 2008 at 7:40 PM
  4. Hoxxy
    Joined:
    Aug 26, 2008
    Posts:
    69
    Referrals:
    0
    Sythe Gold:
    0

    Hoxxy Member
    Banned

    Mouse Click and Mouse Move.

    There was a post like this.. with a source code.. maybe you can look in that to get the code?
     
  5. Unread #3 - Aug 29, 2008 at 3:58 PM
  6. -Ken-
    Referrals:
    0

    -Ken- Guest

    Mouse Click and Mouse Move.

    Alright, thank you, I might just be imaging that code to (aka one doesn't exist).
     
  7. Unread #4 - Aug 29, 2008 at 4:25 PM
  8. jdsfighter
    Joined:
    Jan 21, 2007
    Posts:
    603
    Referrals:
    0
    Sythe Gold:
    0

    jdsfighter Forum Addict
    Visual Basic Programmers

    Mouse Click and Mouse Move.

    Hmm I posted this code ages ago, let me dig it up.

    EDIT:

    Here you are
    Code:
    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 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
    USAGE:
    Code:
    'Left Click 
    Private Sub Command1_Click()
    LeftClick
    End Sub
    'Move mouse
    Private Sub Command_Click()
    SetCursorPos 100,100
    End Sub
    'Move and click
    Private Sub Command3_Click()
    LeftClick1 100,100
    End Sub
    
     
  9. Unread #5 - Aug 30, 2008 at 12:31 PM
  10. -Ken-
    Referrals:
    0

    -Ken- Guest

    Mouse Click and Mouse Move.

    Wow, that first code is A LOT of code. Thank you very much.

    EDIT: Whenever I am to use the code, it comes up with errors :p. I'll debug it.

    EDIT # 2: This is for Visual Basic 6.0, correct?
     
  11. Unread #6 - Aug 30, 2008 at 12:51 PM
  12. Darthatron
    Joined:
    May 22, 2006
    Posts:
    1,612
    Referrals:
    3
    Sythe Gold:
    0

    Darthatron Massive Troll
    Retired Sectional Moderator Visual Basic Programmers

    Mouse Click and Mouse Move.

    What are the errors? I hope you put it in a module. >_>

    And yes, it's for VB6
     
< Help with Idea | IRC Client [Update Pics (GUI) More features!] >

Users viewing this thread
1 guest


 
 
Adblock breaks this site