Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

The status of mouse buttons

Total Hit ( 3398)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Visual Basic lets you test the state of mouse buttons only inside a MouseDown, MouseMove, or MouseUp event procedure. To determine the current state of mouse buttons you can use one of the following functions:

Click here to copy the following block
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As _
  Integer

Function LeftButton() As Boolean
  LeftButton = (GetAsyncKeyState(vbKeyLButton) And &H8000)
End Function

Function RightButton() As Boolean
  RightButton = (GetAsyncKeyState(vbKeyRButton) And &H8000)
End Function

Function MiddleButton() As Boolean
  MiddleButton = (GetAsyncKeyState(vbKeyMButton) And &H8000)
End Function

If you prefer, you can use the following function, which returns the state of all three buttons as a bit-coded field, in the same format as the Button argument passed to mouse event procedures:

Click here to copy the following block
Function MouseButton() As Integer
  If GetAsyncKeyState(vbKeyLButton) < 0 Then
    MouseButton = 1
  End If
  If GetAsyncKeyState(vbKeyRButton) < 0 Then
    MouseButton = MouseButton Or 2
  End If
  If GetAsyncKeyState(vbKeyMButton) < 0 Then
    MouseButton = MouseButton Or 4
  End If
End Function


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.