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