[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mouse.Button , ensure correct right button value


On Tue, 2 Apr 2024 at 12:59, Gianluigi <gradobag@xxxxxxxxxxx> wrote:

> Il 02/04/24 12:14, Bruce Steers ha scritto:
> > I have been helping someone dealing with a mouse event issue and pointed
> > out a possible error in their code.
> >
> > They were using "If Mouse.Button = 2" to detect a right mouse click.
> >
> > I said that could be the problem as on my machine right click is
> > Mouse.Button = 3
> > They replied that no, right click is Mouse.Button  = 2 on their machine.
> >
> > Meaning my recent game that uses Mouse.Button to detect clicks is
> > incorrectly coded as I am assuming right click is 3
> >
> > So my question would be, is there a way to detect what Mouse.Button
> > value a right click will be?
> >
> > Mouse.Left and Mouse.Right were not good enough as the detection in the
> > MouseDown needs to detect the click , and if you left click while
> > holding right mouse down then the Mouse.Button will be  1 but Mouse.Left
> > and Mouse.Right will both be true so Mouse.Button was a better option.
> > But i did not realize the value of right button can change :-\
> >
> > I'm now thinking of some workarounds but I'm wondering if there may be a
> > simple way to obtain the valid Button values .
> >
> > Respects.
> >
> > Happy Easter
> > BruceS
> >
>
> I don't know if I understand correctly, but could such a thing help?
>
> Public Sub Form_MouseDown()
>
>    If Not Mouse.Right Then Return
>    Print "You pressed on the right button!"
>
> End
>
> Regards
> Gianluigi

No, thanks but it's not good enough as I explained.

If i am holding the right mouse button down and i then press the left
button then that code will register Mouse.Right is True
but it was not the button that was just pressed,
If that makes sense.

Mouse.Right and Mouse.Left are not really button "Click" detection they are
button "Is Down" detection and the difference is i need to know what was
just "Clicked" not what is held down.
I'm thinking something like this...

Private $iRight As Integer = -1

Public Sub Form_MouseDown()

  If $iRight = -1 Then
  Select Mouse.Button
    Case 2
      If Mouse.Right And If Not Mouse.Middle Then $iRight = 2 Else $iRight
= 3
    Case 3
      If Mouse.Right And If Not Mouse.Middle Then $iRight = 3
  End Select
  Endif

End

Then once $iRight is not -1 i know exactly what Mouse.Button is right click

Respects
BruceS

Follow-Ups:
Re: Mouse.Button , ensure correct right button valueGianluigi <gradobag@xxxxxxxxxxx>
Re: Mouse.Button , ensure correct right button valueBruce Steers <bsteers4@xxxxxxxxx>
References:
Mouse.Button , ensure correct right button valueBruce Steers <bsteers4@xxxxxxxxx>
Re: Mouse.Button , ensure correct right button valueGianluigi <gradobag@xxxxxxxxxxx>