How to assign keyboard buttons within a script

Have you looked at the example tool I just recently posted (6 days ago) in this forum ?
It traps SHIFT and CTRL modifiers to mouse button clicks in order to add or subtract from a selection set.

Use version 2 …
[Example] A simple FaceSniffer tool extension - #2 by DanRathbun

In your case instead of looking for mouse clicks in onLButtonUp, you’ll have case clauses in onKeyUp that test for VK_UP, VK_DOWN, etc., to set set an internal instance variable that would hold a vector along which you’ll draw an edge.
For example …

case key
when VK_UP
  @vec = Y_AXIS
when VK_DOWN
  @vec = Y_AXIS.reverse
when VK_RIGHT
  @vec = X_AXIS
when VK_LEFT
  @vec = X_AXIS.reverse
else
  # ignore key ?
end

And you’ll use the onUserText callback to receive user input from the VCB (aka Measurements input control. “VCB” is an acronym for Value Control Box.)

But to begin with, the tool’s initial state must get an Inputpoint from the user to know where to begin to draw from.

Basically your idea is a variation on a standard Edge drawing tool (ie, “LineTool”).
Trimble has posted an example and tutorial Line Tool. (The tutorials have verbose comments. The examples have little or no commentary, but the code is the same.)

If you do not know how to use GitHub to create a fork etc., then you can simply copy the two files and paste them into your code editor. At GitHub, display the files (each in turn) and on the file toolbar at the right, between the edit (pencil) button and the delete (trash can) button, is the copy button (one page overlapping another.) Use the copy button to copy each file to the clipboard memory and then switch to your code editor and paste it in (CTRL+V).

Make sure to keep the same file and folder structure. The extension registrar file is at the top level (eventually in the “Plugins” folder,) and the “main.rb” file goes into a subfolder that must be the same name as the registrar file.

You can rename the folder and registrar file to some thing like “nickcrush_linetool.rb” and the folder to "“nickcrush_linetool”, but also change the top module to “NickCrush” and the submodule to “LineTool” in each file. Then, in the registrar file, edit the fields of the SketchupExtension object and the comments at the top to reflect your modifications.


Usually we ask such postings be posted in the Commerical and Collaborative Work category.

I am not interested as the feature your talking about is already available in the native Line Tool.

After activating the tool, simply click a point in the model, then one of the LEFT or RIGHT arrow keys to lock an axis inference, then type a value and hit ENTER. The pencil cursor will remain at the start point, so the direction along either axis locked will be controlled by either a positive of negative value. Positive away from the start point, negative towards the start point.

2 Likes