Results 1 to 4 of 4

Thread: Capturing mouse click

  1. #1

    Thread Starter
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Capturing mouse click

    I need to check if the user has clicked the mouse at the beginning of a loop, I know this should be pretty easy but can't seem to do it without activating the forms mouse_down event.

    Cheers.

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    You can use the GetAsyncKeyState() API to find out if a Mouse Button is being depressed, however, if the mouse is over a form or control, it will still Trigger the Mouse_Down event, the only way to stop the event triggering would be to subclass the form and discard the appropriate message(s).

    Example of GetAsyncKeyState():
    VB Code:
    1. Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    2. Private Const VK_LBUTTON = &H1
    3.  
    4. Private Sub Command1_Click()
    5.     If GetAsyncKeyState(VK_LBUTTON) Then
    6.         Debug.Print "Mouse Button Pressed."
    7.     End If
    8. End Sub

  3. #3

    Thread Starter
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092
    As I'm also using a mouse click to start the loop, how can i make this first click be ignored by GetAsyncKeyState(VK_LBUTTON)?

    I've tried assigning GetAsyncKeyState(VK_LBUTTON) to a variable first but this still doesn't work.

    Any ideas?

  4. #4
    Matthew Gates
    Guest
    So you want to ignore the first click, and after that, than start it?

    Try this:

    VB Code:
    1. Private Declare Function GetAsyncKeyState Lib "user32" _
    2. (ByVal vKey As Long) As Integer
    3.  
    4. Private Const VK_LBUTTON = &H1
    5.  
    6. Dim FirstClick As Boolean
    7.  
    8. Private Sub Command1_Click()
    9.     If FirstClick = False Then FirstClick = True: Exit Sub
    10.     If FirstClick = True Then
    11.         If GetAsyncKeyState(VK_LBUTTON) Then
    12.             Debug.Print "Mouse Button Pressed."
    13.         End If
    14.     End If
    15. End Sub
    16.  
    17. Private Sub Form_Load()
    18.     FirstClick = False
    19. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width