The Enter Key and Draw Tools

What about this workaround:

def onUserText(text, view)
  @user_text= text
  puts  "onUserText #{@user_text}"
  puts  "doing text things here"
.
.
  puts  " text things done"
  @user_text = nil
end

def onReturn(view)
  if @user_text.nil?
    puts  "OnReturn #{@user_text}"
    puts "doing your state procedure"
    if  @pointcount >= 2 && @distance
       @state = 1
       self.update_state
    end
  end
end

VK_END is SketchUp constant predefined and varies depending on the OS, so it’d be easy to use ?
Also note that on a MAC a key-down for TAB fails on a MAC, so use key-up for TAB - it’ll work for both OSs.

I know it’s a different direction than you’ve been discussing, but have you considered using a double-click to indicate end-of-input instead of a keypress? It’s caught by Tool#onLButtonDoubleClick. Fredo6 uses it in various of his extensions with good results.

2 Likes

Another alternative (or addition) is a tool specific context menu that has an item for declaring end of point input.


It also seems like allowing the user to have an option for the hotkey might be helpful rather than try to find the key for all users. (Ie, if a future version of SketchUp changes and happens to commandeer the key you’ve [or the user] has chosen, then the user could change the option setting without having to wait for a updated release of your extension.)

In any case, regardless of what key is used I’d strongly recommend to define a custom constant for it, so you can later read the code and clearly see what key it’s supposed to be.

key == VK_TAB

key == VK_CAPS

key == VK_Ö

After some further testing it appears that all I need to do is add this method:

def onReturn(view)
	if  @pointcount >= 2
		@state = STATE_PICK_FINAL
		self.update_state
	end
end

Now when I click return after a dimension entry it does not terminate and goes to the other method (onUserText), whereas if a return is registered after a click of the mouse (new point entry) or even after the return from a dimension entry it jumps into this method and terminates as it should.

Problem solved by John_drivenupthewall and Dezmo, thank-you. Why was I trying to make it so difficult?

P.S. Even though I did not need to use some of these key codes and other techniques I also learned quite a bit about how to deal with this sort of thing and general UI design. Thank-you to all who chimed in and provided insight, hopefully this discussion/thread is helpful to someone else as it has been for me.

1 Like

… because you love a challenge ? :laughing:

2 Likes

No, its because in this case I was initially unaware of the onReturn method and then I was too stubborn or set in my ways to give it try until I had run into a wall.

I need to think more outside the box with these programming puzzles. This is why I come to the forum with my questions, it helps take the blinders off.

You have another solution now, but for what it’s worth, and for your future reference, my three and a half year old iMac Magic Keyboard doesn’t have an End key anywhere in sight.

A Google search finds:

The End button on a Mac Keyboard: Fn + Right Arrow. Hitting the function key with the right arrow will immediately scroll to the very bottom of an open document or page, regardless of how long it is. This is basically the same thing as pressing the End key on a Windows PC, except it’s a keyboard shortcut. (17 Jun 2015).

As Michael Caine might have said “not everybody knows that” (I certainly didn’t), though I do know that Fn + R-arrow takes me to the end of a text document. And though I used PCs for years before getting this iMac, I hadn’t made the connection with the PC End key.

1 Like