borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Paths)Next Topic (How to say automatically \"OK\" when the prompt box \"Save as\" occurs ?) New Topic New Poll Post Reply
AndreaVB Forum : API : How do you simulate a right-click?
Poster Message
Dalgar
Level: Guest


icon How do you simulate a right-click?

Hey, I'm new to these boards, and very new to VB as well. I was just wondering how to have VB simulate a right-click. An example of having it right-click somewhere and left-click elsewhere else would be great. Thanks for any help.

10-08-2003 at 01:57 AM
| Quote Reply
vbgen
Level: Moderator

Registered: 10-10-2002
Posts: 876
icon Re: How do you simulate a right-click?

I'm not sure what you're asking, Dalgar..

Do this:

Start a new project, and create menu..


Go to the form's code..

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then 'left button was clicked
        PopupMenu 'place the menu name here
    Else
    If Button = 2 Then 'right button was clicked
        PopupMenu 'place the menu name here
    End If
    End If
End Sub


____________________________
Been busy trying to take a second degree <--it's not working out...

10-08-2003 at 03:34 PM
View Profile Send Email to User Show All Posts | Quote Reply
Dalgar
Level: Guest

icon Re: How do you simulate a right-click?

Hmm, that's not quite what I was looking for, but now that I see my post, I don't think I was very clear the first time. What I'd like to have is a button. When clicked, it would move the mouse to a certain location and press the right mouse button for me, then would move to another location and press the left mouse button for me. So I'd only have to click the button and the mouse would move and click those two times with me only clicking once. *this is for a game in which I'm trying to make a macro to do the tedious job of fishing * Thanks again for any help.

11-08-2003 at 02:47 AM
| Quote Reply
Asim-GDI GURU
Level: Sage

Registered: 29-07-2005
Posts: 54
icon Re: How do you simulate a right-click?

Its very simple people.Just have to use two API functions : SetCursorPos for moving cursor and SendInput(for Windows NT/2000/XP) and mouse_event(for Windows 95, Windows NT 3.1) for clicking mouse buttons.For more information about these API see :

Mouse Event

Send Input

If you need an example then tell me I'll show you how to use these two API.In my personal view you must use mouse_event, its quit easy to use.  

Regards,
Asim Siddiqui...

15-08-2005 at 10:50 AM
View Profile Send Email to User Show All Posts | Quote Reply
Asim-GDI GURU
Level: Sage

Registered: 29-07-2005
Posts: 54
icon Re: How do you simulate a right-click?

Hey dear I found the solution to your problem.what about an already made module for doing the work you want to do.
make a module and copy the following code in it

Attribute VB_Name = "Module1"
'Created by Stavros Korokithakis
Option Explicit
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)
Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long

Public Const MOUSE_MOVED = &H1
Public Const MOUSEEVENTF_ABSOLUTE = &H8000
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_MIDDLEDOWN = &H20
Public Const MOUSEEVENTF_MIDDLEUP = &H40
Public Const MOUSEEVENTF_MOVE = &H1
Public Const MOUSEEVENTF_RIGHTDOWN = &H8
Public Const MOUSEEVENTF_RIGHTUP = &H10

Sub ClickIt(x As Long, y As Long, Btn As Integer)
'Call this with x,y being coordinates, and button the button
'
'1 is Left button
'2 is Middle Button
'3 is Right Button
SetCursorPos x, y
Select Case Btn
    Case 1
        mouse_event &H6, 0, 0, 3, 3
    Case 2
        mouse_event &H60, 0, 0, 3, 3
    Case 3
        mouse_event &H18, 0, 0, 3, 3
End Select
End Sub

Regards,
Asim Siddiqui..

17-08-2005 at 01:08 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : API : How do you simulate a right-click?
Previous Topic (Paths)Next Topic (How to say automatically \"OK\" when the prompt box \"Save as\" occurs ?) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder