Unable to trigger tool right-click menu shortcut key in Sketchup 2023

After active tool and popup right-click menu.Then pressing C, the console will output “test c”.
But Active tool of draw circles in Sketchup2023.

class TestTool
  def getMenu(menu, flags, x, y, view)
    menu.add_item("Test(&C)") do
      p "test c"
    end
  end
end
Sketchup.active_model.select_tool TestTool.new

First of all, the example is wrong.

Class: Sketchup::Tool is abstract. . You can not sub-class this class because it is not defined by the API.


No. You need to click on the context menu to do so.


The #getMenu method is called by SketchUp to let the tool provide its own context menu, since it is “generated on the fly” you can not assign a shortcut.

You (user) can assign shortcut if the UI #add_context_menu_handler method is used by the code.

You might try using the #onKeyDown method or the #onKeyUp method instead, but you still may have issues, since you wont be able to receive these key presses in a tool event if they are used as a shortcut. (There are plenty of topic about it here…)
Like in your example the “C” is basically assigned to activate the Circle Tool. To be able to use this letter in your Tool, you (the user) need to be un-assign this letter at the UI Preferences.

You need to press SHIFT+C if the item uses “&C”.

As @dezmo says, you cannot use just the C key from a Ruby tool when it is assigned to a shortcut for a native tool. Also, if a application shortcut is assigned to SHIFT+C, then this also will exit your Ruby tool and fire the command assigned to this shortcut.


For keyboard use of context menus, the user can press TAB to give the first item the focus, then either TAB again to subsequent items, (or the down arrow key) … then ENTER to choose the item and fire the command for it.

Here is code to test TABbing through a context menu:

class TestTool
  def getMenu(menu, flags, x, y, view)
    menu.add_item("Test One") do
      p "Test 'One' pressed"
    end
    menu.add_item("Test Two") do
      p "Test 'Two' pressed"
    end
    menu.add_item("Test Three") do
      p "Test 'Threee' pressed"
    end
  end
end
Sketchup.active_model.select_tool TestTool.new

Sorry, I especially realized this class in its file.

@DanRathbun @dezmo

It’s ok.But I don’t think it’s as convenient as before.

I recorded videos in 2022 and 2023, respectively. The right-click shortcut in 2022 was effective, but in 2023, I directly picked up the focus. I suspect it was a bug after changing the QT framework.

I haven’t made any changes to the default shortcut buttons for both versions of SU.

2022

2023