Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2004-11-09
12
Medium Priority
?
1,842 Views
Last Modified: 2011-09-20
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.
Example:
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,

rrbecker
0
Comment
Question by:rrbecker
  • 6
  • 3
  • 2
  • +1
12 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12536381
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.

~IM
0
 
LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 12536545
Hi

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

;-)
Shiju
0
 
LVL 2

Author Comment

by:rrbecker
ID: 12536650
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.

Thanks,

rrbecker
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:rrbecker
ID: 12536719
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.

rrbecker
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12536807
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.

~IM
0
 
LVL 2

Author Comment

by:rrbecker
ID: 12536906
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

rrbecker
0
 
LVL 2

Author Comment

by:rrbecker
ID: 12537048
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.

rrbecker
0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 500 total points
ID: 12537100
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
0
 
LVL 2

Author Comment

by:rrbecker
ID: 12537264
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,

rrbecker
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12538319
Sorry rrbecker,

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

~IM
0
 
LVL 2

Author Comment

by:rrbecker
ID: 12538450
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.

rrbecker
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question