Control-click works, but right-click does not

I have a canvas with moveable and linkable objects on it. I can build a link between them by selecting one, clicking a button to set it as the source, then clicking another object and setting it as the destination. This is working fine, but it is clunky. I would like to be able to do a right click on the source to initiate drawing the link, then click on the destination object to complete the link.

I have a problem in that control-clicking on an object works, but right-clicking does not.

Does anyone have an idea what may be going wrong?

Here is part of the code in the MouseDown event handler. Thanks for any helpful suggestions you can offer.

if SelNode > 0 Then // node was selected from array of nodes on the Canvas
  if WithinNode(SelNode) Then // mouse pointer is within the bounds of the object
    if IsContextualClick Then
      msgbox("Contextual Click")
    else
      msgbox("Left click")
    end if
  end if
end if


You’re using MouseDown when you need to be using ConstructContextualMenu.

2 Likes

mousedown + isContextualClick works just fine for me in a Canvas and DesktopCanvas for right and control + left clicks.
Maybe move your debug test to top of event to ensure nothing else is exiting function.
Also double check your mouse / track pad actual are firing right clicks else where on macOS

What happens if you are using right click to action something other than a popup menu?

The only code lines above these are
Var i As Integer

lastX = x

lastY = y

So I don’t think those can be responsible. Right-click works in all of the other applications that I use on my Mac.

That is what I am doing. I’m not trying to invoke a popup menu. My test case just shows msgboxes.

I don’t want to make a popup menu though. I want to initiate drawing a line by identifying where it starts (and ends).

No harm in trying.
Maybe store the IsContextualClick in a local var so if you are debugging you do not lose the actual value.

Sorry, this was a reply to Tim, “Reply” button does not auto quote

Oops. Sorry.

What macOS version and Xojo Version? I tested on 2025r2 on 15.5

Sounds like a mouse setup issue to me.

Are you sure the mouse isnt set up as left handed?

Are you using a trackpad instead of a mouse?

If it were a mouse setup issue, wouldn’t it manifest in other programs beyond Xojo? Anyway, I had checked the Mouse settings and there is nothing amiss with left and right buttons. To make sure, I changed the button assignments there and the same problem remained, just swapping left for right.

It’s set up as right handed, and it’s a mouse (a Magic Mouse in fact) not a trackpad. I will see if I have another mouse with buttons knocking around, and if so I’ll try that.

I’m using Xojo 2025 r2, on MacOS 15.6.1

Code I use in mousedown:

//right mouse button?
if keyboard <> nil then
if keyboard.asynccontrolkey  then
rbut = true
end if
end if
if IsContextualClick then
rbut = true
end if

has never failed to my knowledge.

I wonder if there is something odd in

if SelNode > 0 Then // node was selected from array of nodes on the Canvas if WithinNode(SelNode) Then// mouse pointer is within the bounds of the object

maybe see what happens here:

dim rbut as boolean
//right mouse button?
if keyboard <> nil then
if keyboard.asynccontrolkey  then
rbut = true
end if
end if
if IsContextualClick then
rbut = true
end if

if rbut then
 msgbox("Contextual Click")
else
 msgbox("Left click")
end if

if SelNode > 0 Then // node was selected from array of nodes on the Canvas
  if WithinNode(SelNode) Then // mouse pointer is within the bounds of the object
    if rbut Then
      msgbox("Contextual Click and selected")
    else
      msgbox("Left click and selected")
    end if
  end if
end if

Curiouser and curiouser. I will give that code a go, but in the meantime I have some information about mouse setup. The mouse I normally use is a rechargeable Bluetooth Magic Mouse, version 3.1.1, and the right click fails here. I also tried another Bluetooth Magic Mouse, (with AA batteries) version 3.0.6. Using this mouse my program responds to a right click as intended.

I’m going to sleep on this.

Thanks for the input so far everyone.

Ian.

–

1 Like

This week I set up a ConstructContextualMenu on a Canvas on a DesktopContainer plus a ConstructContextualMenu on the DesktopContainer itself. I found that I could only control-click the canvas and not right-click it to show the menu.

I removed the ConstructContextualMenu from the Canvas and left it for the DesktopContainer and it’s all working now ie do you have two ConstructContextualMenu’s that are conflicting?

2 Likes