+ Reply to Thread
Results 1 to 2 of 2

Mouse Coordinates in userform

Hybrid View

  1. #1
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Question Mouse Coordinates in userform

    Hi All,

    i have search the threads and i need a bit of help.

    it's quiet in the office for obvious reasons and so i've decided to make a spot the difference userfrom lol.

    i was wondering.

    when i click on the picture how can i get the coordinates of the mouse to populate in label1 and lable 2 (x and y respectively)

    from here i will use a select case statement to decide if the user has clicked on an altered part of the picture?

    hope thats clear enough

    thanks for reading and for any help
    Last edited by Macdave_19; 12-31-2008 at 04:58 AM.
    Mr MaGoo
    Magoo.Inc MMVII

    If i've helped please add to my Rep by Clicking on the Blue Scales in the top right hand corner of the post

  2. #2
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Eureka

    Found this code and i'm applying this to my idea of spot thr difference:

    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)
    Type POINTAPI 'Declare types
    x As Long
    y As Long
    End Type
    
    Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long 'Declare API
    Const MOUSEEVENTF_LEFTDOWN = &H2
    Const MOUSEEVENTF_LEFTUP = &H4
    Const MOUSEEVENTF_MIDDLEDOWN = &H20
    Const MOUSEEVENTF_MIDDLEUP = &H40
    Const MOUSEEVENTF_RIGHTDOWN = &H8
    Const MOUSEEVENTF_RIGHTUP = &H10
    Sub Main()
    Dim z As POINTAPI 'Declare variable
    Dim xpos As Long, ypos As Long
    GetCursorPos z 'Get Coordinates
    xpos = CLng(z.x)
    ypos = CLng(z.y)
    If ListVar1 = "Release" Then
    Select Case ListVar2
    Case "Left"
    mouse_event MOUSEEVENTF_LEFTUP, xpos, ypos, cButt, dwEI
    Case "Right"
    mouse_event MOUSEEVENTF_RIGHTUP, xpos, ypos, cButt, dwEI
    Case "Center", "Middle"
    mouse_event MOUSEEVENTF_MIDDLEUP, xpos, ypos, cButt, dwEI
    End Select
    Else
    Select Case ListVar2
    Case "Left"
    mouse_event MOUSEEVENTF_LEFTDOWN, xpos, ypos, cButt, dwEI
    Case "Right"
    mouse_event MOUSEEVENTF_RIGHTDOWN, xpos, ypos, cButt, dwEI
    Case "Center", "Middle"
    mouse_event MOUSEEVENTF_MIDDLEDOWN, xpos, ypos, cButt, dwEI
    End Select
    End If
    End Sub
    
    Sub Picture1_Click()
    Dim z As POINTAPI 'Declare variable
    Dim xpos As Long, ypos As Long
    GetCursorPos z 'Get Coordinates
    xpos = CLng(z.x)
    ypos = CLng(z.y)
    Range("Xaxis").Value = xpos
    Range("Yaxis").Value = ypos
    End Sub
    HTH people

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1