intercept mouse click

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

intercept mouse click

Post by sal21 »

i use this to inetrcept the mouse click:

in bas
'MOUSE CLICK
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public Const VK_LBUTTON = &H1
Public Const VK_RBUTTON = &H2

but the code return always left! in:
Private Sub MSFlexGrid1_Click()

If GetAsyncKeyState(VK_LBUTTON) Then
With Me.MSFlexGrid1
Me.LCOLONNA.Caption = .Col
Me.LRIGA.Caption = .Row
End With
End If

End Sub
note:
in need in msflexgrid click event not in mouse_down event

User avatar
SpeakEasy
4StarLounger
Posts: 536
Joined: 27 Jun 2021, 10:46

Re: intercept mouse click

Post by SpeakEasy »

Can you explain why you "need in msflexgrid click event not in mouse_down event"? Could you, for example, use the mouse_up event, and thus avoid needing to make an API call (I'm a big user of the API myself - when appropriate; not sure that it is necessary here, though).

And knowing how an API function works is also important - and your use of GetAsyncKeyState is a) not doing what you think it is; but is b) is fooling you into thinking it is (sort of) working because you don't understand the return values. I'm guessing it is a copy and paste solution.

Consider the answer to the following question: exactly when does a VB Click event occur?

User avatar
SpeakEasy
4StarLounger
Posts: 536
Joined: 27 Jun 2021, 10:46

Re: intercept mouse click

Post by SpeakEasy »

Hello?

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: intercept mouse click

Post by sal21 »

SpeakEasy wrote:
15 Mar 2022, 21:38
Hello?
Sorry me, in very busy