How to use GetAsyncKeyState or GetKeyState to Trap Right Mouse Click?

Hi All,

This may be silly and I appologize ahead of time, but  how do I use GetAsyncKeyState or GetKeyState to Trap Right Mouse Click.

I guess the real question is what is the CONSTANT that I use for a Right-Mouse-Click.
Private Const VK_SHIFT = &H10
Private Const VK_MENU = &H12
Private Const VK_CONTROL = &H11

What do I use for a Right-Mouse-Click?

Thanks in advance,

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
You don't.  GetAsyncKeyState() and GetKeyState() deal with the keyboard, not the mouse.

Explain more what you are tyring to do and perhaps we can come up with a solution.

Shiju SasidharanAssoc Project ManagerCommented:

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Select Case Button
        Case vbRightButton
                'vbRightButton = 2
            Debug.Print "Right Button Pressed"
        Case vbLeftButton
                'vbLeftButton = 1
            Debug.Print "Left Button Pressed"
        Case vbMiddleButton
                'vbMiddleButton = 4
            Debug.Print "Middle Button Pressed"
    End Select
End Sub

rrbeckerAuthor Commented:
Hi ~IM

How you doing? Thanks for your help with my previous question.

OK, Well because of the great solution you provided me (Sending data from my program to another) I decided to try 'Popping' up  'Menu' of item any time I detected a Right-Mouse-Click.
The user would select one of the item from my Menu and the data associated with it would be sent to the current active window.

My thought is to give them a 'Short-Cut' for a few Menu Items that they use all of the Time.

The original application that you helped me with works just fine, I'm just trying to spruce it up a bit.

BTW, application deals with populating On-Line-Forms.


Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

rrbeckerAuthor Commented:
Hi Shiju,

Thanks for the reply, however, my application basicially will run in the background and will need
to Monitor the Mouse activity for all Running applications. Your solution wooks well for getting the
Mouse clicks for 'MY' application.

Any other ideas are always appreciated.

Mike TomlinsonMiddle School Assistant TeacherCommented:
So you are trying to detect a Right Mouse Click in a webform?

There are ways of trapping the right mouse click using system wide hooks but this is very difficult in VB6.

If you are only dealing with webforms then you might want to consider instead building an IE Add-On, otherwise known as a Browser Extension or Helper Object.  These are applications that actually load "inside" IE and allow you special access to the webpage.  From there it would be easy to detect a right click on a webform textbox and allow you to popup a context menu with your fill-in values.

I haven't done this myself so I can't help you there.  I'll see what info I can find on the topic however.

rrbeckerAuthor Commented:
Hi ~IM

While populating WebForms is a major consideration it is not the only one. E-Mail tools are another.

I mentioned at one time that I had 'Tinkered' with VB.NET and that I might try implementing this application in .Net at a later date. If this function is 'More' easily done there, then maybe I'll hold off until then.

Thanks for you valued input

rrbeckerAuthor Commented:
Hi Again ~IM,

For the Short Term I guess I'll add the 'Popup' display to a Function Key so..... what is the
CONSTANT for Function Keys.

How about adding a timer control:

Option Explicit

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Const VK_LBUTTON = &H1
Private Const VK_RBUTTON = &H2

Private Sub Form_Load()
    Timer1.Interval = 100
End Sub

Private Sub Timer1_Timer()
    If GetAsyncKeyState(VK_RBUTTON) Then
        MsgBox "Right click!"
    End If
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rrbeckerAuthor Commented:
Hi Vinnyd79,

Yes, that was what I was looking for.( Const VK_RBUTTON = &H2 )  I will award you the points,

BTW, where do I get or how do I derive these CONSTANTS?

Thanks again the Help,

Mike TomlinsonMiddle School Assistant TeacherCommented:
Sorry rrbecker,

I was definitely wrong on GetAsyncKeyState() not being able to detect a right mouse click.

rrbeckerAuthor Commented:
Hi ~IM,

No problem, You have already helped more than I could have hoped for.

As far as the .NET attempt.... I am going to try to start on it in about a week or so depending upon how quick I can wrap up this latest add-on.

Thanks again for all you past help.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.