SKUI Textbox :onkey event getkey


#1

Hi

I am trying to figure out is there a way, without changing SKUI wraper from thomthom, to get “ENTER” press event.

I am using SKUI in my plugin, and because i am not very experienced in ruby, its very helpful. But i cant get this work.

Any help will be welcome.
Best regards

my code:

def testwindow
  window = SKUI::Window.new( title: 'Test Window',
                                width: 500,
                                height: 210,
                                resizable: false)

  txt = SKUI::Textbox.new( 'nothing' )
  txt.position( 10, 10 )
  txt.width = 70
  txt.on( :change) { |c| @promien = c.value }
  txt.on( :keyup)     { |c| puts "keyup: #{c.value} '#{STDIN.getc}'"    }
  txt.on( :keydown)   { |c| puts "keydown: #{c.value}"  }
  txt.on( :keypress)  { |c| puts "keypress: #{c.value}" }

  window.add_control( txt )

end

#2

I am not aware that STDIN.getc works in SketchUp. And even if it worked, you wouldn’t see the puts until you have found out where to fill in a line to getc to satisfy it and resume Ruby execution.
You should try it again leaving that away.


#3

When you press ENTER (or TAB) in a textbox control, focus moves to the next control in the tab order, so try trapping the :blur event.

txt.on(:blur) {
  if ( txt.value.empty? rescue true )
    puts "Nothing entered, ... nothing gained."
  else
    puts "The value entered was \"#{txt.value}\""
  end
}

#4

P.S. - It does not seem that the event keycodes are being sent to the Ruby-side control callback blocks. If they were, you could test for code 13.


#5

SDIN.getc “semi-works”. not return error byt return NIL

Using :blur would be a workaround if ther were only one field. This window contain fields for 5 parameters, and user may change more than one before apply.

and this is my main concern. This imply that I need modify wraper itself

Thank you


#6

Well, then how about an :focus event on your “Apply” button ?