Force Mouse Click

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • devonknows
    New Member
    • Nov 2006
    • 137

    Force Mouse Click

    Hey all, long time no see :), erm what it is i have a DirListBox Control on my form and i need to make the mouse left click before showing the popup menu, so the item that the user has right clicked on is highlighted before showing the popup menu, or if there is a better way of doing this then forcing the mouse to click before using the PopupMenu Method, for example the x and y of the mouse ... any help would be greatly appreciated.

    Kind Regards as Always,
    Devon.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by devonknows
    Hey all, long time no see :), erm what it is i have a DirListBox Control on my form and i need to make the mouse left click before showing the popup menu, so the item that the user has right clicked on is highlighted before showing the popup menu, or if there is a better way of doing this then forcing the mouse to click before using the PopupMenu Method, for example the x and y of the mouse ... any help would be greatly appreciated.

    Kind Regards as Always,
    Devon.
    Although I forget the name, there certainly are API calls to translate mouse x/y coordinates to other things, such as the control which was clicked. Not sure though how you would determine what entry you were positioned over in the list.

    I have a sneaking suspicion that you may end up having to make your own equivalent of the dirlistbox, or obtain another control from somewhere. However, in browsing the properties for the DirListBox, I see TopIndex, which sounds as though it may be helpful in your endeavour, in conjunction with the aforementioned mouse coordinates.

    Comment

    • vincey92
      New Member
      • Feb 2008
      • 11

      #3
      i know how to move the mouse it is like this:

      cursor.position = new point(150,150)

      i am also looking for how to force a mouse click event

      i cant find any code either. thx

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by vincey92
        i know how to move the mouse it is like this:

        cursor.position = new point(150,150)

        i am also looking for how to force a mouse click event
        Thanks vincey92.

        What version of VB is that? It must be later than VB6, because (AFAIK) there's no Cursor object in that version.

        Sending a mouse click would be done using the SendMessage API call(s), I expect.

        Comment

        • devonknows
          New Member
          • Nov 2006
          • 137

          #5
          Hi, i did actually find the solution for this, sorry i should have reposted it, But VB6 does not have the Cursor.Posiotio n, im assuming VB.Net?, if you can convert it this is what i have for vb6

          Place the following Code into a Module.

          [CODE=vb]
          'Module
          Option Explicit
          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 Sub ForceMouseClick (ByVal dX As Long, ByVal dY As Long)
          Dim mouse_x As Long
          Dim mouse_y As Long
          mouse_x = CLng(dX * 65535 / Screen.Width)
          mouse_y = CLng(dY * 65535 / Screen.Height)
          mouse_event _
          MOUSEEVENTF_LEF TDOWN Or _
          MOUSEEVENTF_LEF TUP, _
          mouse_x, mouse_y, 0, 0
          End Sub[/CODE]

          The Reason i needed this code was so that if someone right clicked on a listbox, it would left click first to highlight the option, and then bring up the popup menu i assigned to it, ill post you the code that i have used minus some things, to give you a better understanding.

          The following code goes inside your form (The Following Code Demonstrates Force Click for a listbox called 'lstBrowse')
          [CODE=vb]
          Private Sub lstBrowse_Mouse Down(Button As Integer, Shift As Integer, X As Single, Y As Single)
          If Button = 2 Then
          'Use the X & Y from the lstBrowse_Mouse Down
          Call ForceMouseClick (X, Y) 'Force Click
          DoEvents 'Just to make sure it clicks
          Me.PopupMenu mnuEdit, , , , mnuEditRecord 'Call The Popup Menu
          End If
          End Sub
          [/CODE]

          I hope this is of help to you
          Kind Regards
          Devon

          Comment

          • daniel aristidou
            Contributor
            • Aug 2007
            • 494

            #6
            Um why not...check that an item is selected....bef ore allowing the popupmenu to show... ie nothing selected..no popupmenu on right click?

            Comment

            • devonknows
              New Member
              • Nov 2006
              • 137

              #7
              Originally posted by daniel aristidou
              Um why not...check that an item is selected....bef ore allowing the popupmenu to show... ie nothing selected..no popupmenu on right click?
              Its more to the fact of if you move the mouse of another item in the list box, whilst an item further up is still select and right click, the popupmenu reacts for the one that you have selected, not the one your are hovering over, so by forcing the mouse to left click first you highlight the the item you are currently hovering over.

              Its just to make it easier on the user, i know i get frustrated when i have to click something twice just to get one menu (left click then right click)

              Kind Regards
              Devon

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Originally posted by devonknows
                Its just to make it easier on the user, i know i get frustrated when i have to click something twice just to get one menu (left click then right click)
                Yes, that sort of thing can be very annoying, and it sounds as though you've got a nice solution there.

                Thanks very much for posting it.

                (I think it will require very little conversion for VB6. Will try to do as soon as I have a chance, and post the results here for anyone else who comes searching.)

                Comment

                • vincey92
                  New Member
                  • Feb 2008
                  • 11

                  #9
                  thanx guys im using vb2008 express will that force mouse down stuff still work? i no that the movement of the mouse position still worx cos iv tested that but i still would like 2 no bout hte force mouse clikc

                  Comment

                  Working...