Class: Sketchup::Toolis 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 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.
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
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.