B4J Question (QUESTION) Detecting Right mouse click in customviewclass

Marc De Loose

Member
Licensed User
Longtime User
Hi,

What is the best way to detect if a mouse click was a right click?
The following code detects left or right as the same click
B4X:
Private Sub mBase_Touch (Action As Int, X As Float, Y As Float)
    ' HANDLE CLICK AND LONGCLICK
    'Log("Action = " & Action)

    Select Action
        Case mBase.TOUCH_ACTION_DOWN
            Log("Action = " & Action)
            mTimeDown = DateTime.Now
            tmrClick.Enabled = True
           
        Case mBase.TOUCH_ACTION_UP
            If DateTime.Now - mTimeDown <= mClickTime Then
                If xui.SubExists(mCallBack, mEventName & "_Click", 0) Then
                    CallSubDelayed(mCallBack, mEventName & "_Click")
                    tmrClick.Enabled = False
                End If
            End If
    End Select

I suppose I could add a global variable in Main (public lastMouseEvent as MouseEvent) and check that in my mBase_touch(....) sub. [Edit] Just tried that and it does not work.

But is there a better way?
 
Last edited:

teddybear

Well-Known Member
Licensed User
You can add MouseClicked event to detect it
B4X:
Private Sub mbase_MouseClicked (EventData As MouseEvent)
    If EventData.SecondaryButtonPressed Then
        Log("Right clicked")
    End If
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…