By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,062 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,062 IT Pros & Developers. It's quick & easy.

Force Mouse Click

devonknows
100+
P: 137
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.
May 4 '07 #1
Share this Question
Share on Google+
8 Replies


Expert 5K+
P: 8,434
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.
May 5 '07 #2

vincey92
P: 11
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
Feb 1 '08 #3

Expert 5K+
P: 8,434
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.
Feb 2 '08 #4

devonknows
100+
P: 137
Hi, i did actually find the solution for this, sorry i should have reposted it, But VB6 does not have the Cursor.Posiotion, im assuming VB.Net?, if you can convert it this is what i have for vb6

Place the following Code into a Module.

Expand|Select|Wrap|Line Numbers
  1. 'Module
  2. Option Explicit
  3. Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dX As Long, ByVal dY As Long, _
  4.                                                     ByVal cButtons As Long, ByVal dwExtraInfo As Long)
  5.  
  6. Public Sub ForceMouseClick(ByVal dX As Long, ByVal dY As Long)
  7.         Dim mouse_x As Long
  8.         Dim mouse_y As Long
  9.         mouse_x = CLng(dX * 65535 / Screen.Width)
  10.         mouse_y = CLng(dY * 65535 / Screen.Height)
  11.         mouse_event _
  12.             MOUSEEVENTF_LEFTDOWN Or _
  13.             MOUSEEVENTF_LEFTUP, _
  14.             mouse_x, mouse_y, 0, 0
  15. End Sub
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')
Expand|Select|Wrap|Line Numbers
  1. Private Sub lstBrowse_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2.     If Button = 2 Then
  3.         'Use the X & Y from the lstBrowse_MouseDown
  4.         Call ForceMouseClick(X, Y)                  'Force Click
  5.         DoEvents                                    'Just to make sure it clicks
  6.         Me.PopupMenu mnuEdit, , , , mnuEditRecord   'Call The Popup Menu
  7.     End If
  8. End Sub
  9.  
I hope this is of help to you
Kind Regards
Devon
Feb 2 '08 #5

daniel aristidou
100+
P: 491
Um why not...check that an item is selected....before allowing the popupmenu to show... ie nothing selected..no popupmenu on right click?
Feb 2 '08 #6

devonknows
100+
P: 137
Um why not...check that an item is selected....before 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
Feb 2 '08 #7

Expert 5K+
P: 8,434
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.)
Feb 3 '08 #8

vincey92
P: 11
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
Feb 7 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.