(SketchUp 2026) VCB loses focus after pressing Tab in SketchUp tool

In SketchUp 2026, when using a custom Ruby tool, pressing the Tab key in a specific state (@statestate == 2 in :fixed_height mode) causes the Value Control Box (VCB) to lose focus, preventing user input for dimensions (e.g., depth). The issue appears to be a bug in SketchUp 2026, where the Tab key incorrectly shifts focus to other UI elements (e.g., toolbars or tabs) instead of maintaining focus on the VCB.
Without Sketchup.focus, the focus shifts to other UI elements, making VCB unusable.
Workaround in my example:
To resolve the issue, a timer (UI.start_timer) with a 0.1-second delay is used to reinitialize the VCB and restore focus using Sketchup.focus. This ensures the VCB is ready for input after the Tab key event is processed.

Example Code:

def onKeyDown(key, rpt, flags, view)
  if key == VK_TAB && @state == 2 && @drawing_mode == :fixed_height && @base_pts_original
    @thickness_offset_mode = @thickness_offset_modes[(@thickness_offset_modes.index(@thickness_offset_mode) || 0) + 1 % @thickness_offset_modes.length]
    apply_thickness_offset
    update_prompt
    Sketchup::set_status_text @prompt, SB_PROMPT
# Use a delayed timer to initialize the VCB
    UI.start_timer(0.1, false) do
      Sketchup::set_status_text("Depth", SB_VCB_LABEL)
      Sketchup::set_status_text("", SB_VCB_VALUE)
# Explicitly return focus to SketchUp
      Sketchup.focus
      view.invalidate
    end
    view.invalidate
    return true
  end
  false
end

Is there another way and am I doing something wrong?

It looks good. I.e., you are trapping the TAB in a specific tool state and preventing it from bubbling up. This would be a good coding pattern.

It is normal for TAB to move focus for GUI elements that have a TAB stop. However, Sketchup’s VCB does not normally need to have the input focus in order to accept values. (Meaning the user does not need to click on the VCB to give it focus.)

Do you see different behavior in older SketchUp versions?


BTW, please use the ```ruby block form delimeters for code when posting in the forum:

In SketchUp 2025 and 2024, the Tab key does not require additional focus in the tool. This problem only appeared in SketchUp 2026.
I know about this bug in SketchUp 2026 from other users who use other plugins where the Tab key is involved. It does not work cyclically, and after completing the task, it loses the tool focus and goes to other active tabs or fields.

Has this bug then been reported in the API Issue Tracker at GitHub?
(I do see a report that there are problems with the ENTER key in Tools.)

Also, historically, the onKeyDown callback has always had issues with certain keys.
If your tool is not trapping a held key down, try using the onKeyUp callback instead to detect key clicks.