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

**URL:** <https://forums.sketchup.com/t/unable-to-trigger-tool-right-click-menu-shortcut-key-in-sketchup-2023/227140>\
**Category:** Ruby API\
**Tags:** sketchup, sketchup-2023\
**Created:** [April 15, 2023, 6:28am UTC](https://forums.sketchup.com/t/unable-to-trigger-tool-right-click-menu-shortcut-key-in-sketchup-2023/227140 "2023-04-15T06:28:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![javalitterboy](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/javalitterboy/32/170896_2.png) [@javalitterboy](https://forums.sketchup.com/u/javalitterboy)\
**Post date:** [April 15, 2023, 6:28am UTC](https://forums.sketchup.com/t/unable-to-trigger-tool-right-click-menu-shortcut-key-in-sketchup-2023/227140/1 "2023-04-15T06:28:56Z")

</div>

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.

```ruby
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

```

---

<div class="post-metadata">

**Author:** ![dezmo](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/dezmo/32/51058_2.png) [@dezmo](https://forums.sketchup.com/u/dezmo)\
**Post date:** [April 15, 2023, 8:09am UTC](https://forums.sketchup.com/t/unable-to-trigger-tool-right-click-menu-shortcut-key-in-sketchup-2023/227140/2 "2023-04-15T08:09:11Z")

</div>

First of all, the example is wrong.

> [@javalitterboy](#):
>
> `class TestTool < Sketchup::Tool`

[Class: Sketchup::Tool](https://ruby.sketchup.com/Sketchup/Tool.html) **is abstract.**. _You can not sub-class this class because it is not defined by the API._

* * *

> [@javalitterboy](#):
>
> Then pressing C, the console will output “test c”.

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

* * *

The [#getMenu](https://ruby.sketchup.com/Sketchup/Tool.html#getMenu-instance_method) 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](https://ruby.sketchup.com/UI.html#add_context_menu_handler-class_method) method is used by the code.

You might try using the [#onKeyDown](https://ruby.sketchup.com/Sketchup/Tool.html#onKeyDown-instance_method) method or the [#onKeyUp](https://ruby.sketchup.com/Sketchup/Tool.html#onKeyUp-instance_method) 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.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [April 15, 2023, 2:14pm UTC](https://forums.sketchup.com/t/unable-to-trigger-tool-right-click-menu-shortcut-key-in-sketchup-2023/227140/3 "2023-04-15T14:14:16Z")

</div>

> [@javalitterboy](#):
>
> Then pressing C, the console will output “test c”, …  
> but Active tool of draw circles in Sketchup2023.

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:

```ruby
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

```

---

<div class="post-metadata">

**Author:** ![javalitterboy](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/javalitterboy/32/170896_2.png) [@javalitterboy](https://forums.sketchup.com/u/javalitterboy)\
**Post date:** [April 19, 2023, 6:06am UTC](https://forums.sketchup.com/t/unable-to-trigger-tool-right-click-menu-shortcut-key-in-sketchup-2023/227140/4 "2023-04-19T06:06:36Z")

</div>

> [@dezmo](#):
>
> [Class: Sketchup::Tool](https://ruby.sketchup.com/Sketchup/Tool.html) **is abstract.**. _You can not sub-class this class because it is not defined by the API._

Sorry, I especially realized this class in its file.

---

<div class="post-metadata">

**Author:** ![javalitterboy](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/javalitterboy/32/170896_2.png) [@javalitterboy](https://forums.sketchup.com/u/javalitterboy)\
**Post date:** [April 19, 2023, 6:15am UTC](https://forums.sketchup.com/t/unable-to-trigger-tool-right-click-menu-shortcut-key-in-sketchup-2023/227140/5 "2023-04-19T06:15:14Z")

</div>

@DanRathbun @dezmo

> [@DanRathbun](#):
>
> You need to press **SHIFT** + **C** if the item uses “&C”.

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.

> [@DanRathbun](#):
>
> 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.

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

# 2022

# 2023
