There are several Examples of Tool .rb files shipped with Sketchup - e.g. LineTool.
These will show how to construct and then call a Tool class, which then has access to lots of methods relating to user input - mouse, keys etc - without you having to reinvent them from scratch...
Also see the API docs... https://developers.google.com/sketchup/docs/ourdoc/tool
💡 LightUp 7.1 | SketchUp's only real-time renderer that uses object-based rendering
Download Trial
C