We’re working on a custom tool that already has a primary action bound to left-click and now we decided to bind a secondary action to the right-click button being pressed (instead of showing the context menu).
According to the API documentation, we should use a combination of
onRButtonDown/Up to disable the default context menu and react to the event. However, we are not able to make this work.
The context menu still shows up
getMenuis defined but empty, the default menu appears (from the API doc, we expected it not to)
getMenuadds some dummy items to the menu, a custom menu does show up (which shows that the method is called)
onRButtonDown/onRButtonUp events are not called
- but this might be due to the menu showing up?
What’s a bit worrying is that it works fine with SketchUp 2017 but it does not with recent versions (we tried SU 2020 and 2021.1, on Windows, on two computers).
You can paste this in the Ruby console to reproduce the issue:
class TestTool def onLButtonDown(_flags, _x, _y, view) puts 'LEFT DOWN' end def onLButtonUp(_flags, _x, _y, view) puts 'LEFT UP' end def onRButtonDown(_flags, _x, _y, view) puts 'RIGHT DOWN' # Doesn't get called end def onRButtonUp(_flags, _x, _y, view) puts 'RIGHT UP' # Doesn't get called end def getMenu(menu, flags, x, y, view) # Implemented to prevent a context menu appearing on right click # ... But the default menu still shows up # We also tried both signatures, just in case: # - getMenu(menu) # - getMenu(menu, flags, x, y, view) # but it doesn't change the issue end end Sketchup.active_model.tools.push_tool(TestTool.new)
Are we using the API in an appropriate manner?
Thanks a lot for any help, we’re a bit stuck right now