Using ; (semicolon) list separator in a better way in Tool [Hack]

Using ; (semicolon) list separator in a better way in Tool [Hack]

Symptom:

For example in a native Rectangle Tool or Scale Tool you can type in more values separated by list separator to get desired rectangle or scaling in one step.

However it is not (or not the same way) possible if you are using a certain language (regional) settings and keyboard language, where the list separator is a semicolon ;, and to type in a list separator you need to use Alt Gr (or Ctrl + Alt) + key right side of m.

Here, in the above mentioned Tools, the Ctrl and/or Alt keys are used also as modifier key, therefor pressing them to type in the desired “letter” will modify the Tool behaivor. This one I do not like.

Scale tool animation: Alt Gr ; behavior's

scaletool_bad

And yes, I know exactly how to handle it with diferent workarouds e.g. type the values after the mouse click, use external keyboard with utility… etc.
But I would like to use it like e.g. English people does.

Certainly the best would be if these native tools can handle the regional setting properly. But since it’s been that way for 20 years or so, I don’t see much of a chance for improvement.

However the gooal is this post to show to the Extension developers one possible way to handle it better. (…perhaps it will also attract the attention of SketchUp developers.)

Idea:

AltGrHack

I hope no need too much explanation.
As usual: NO warranties! Use on your own risk!

module Dezmo
module DezmoHackListSeparator
  extend self
  
  LIST_SEP ||= Sketchup::RegionalSettings.list_separator
  
  def run
    Sketchup.active_model.select_tool( DezmoTypeListSeparator.new )
  end
  
  class DezmoTypeListSeparator
    
    def initialize
      view = Sketchup.active_model.active_view
      reset(view)
    end
    
    def reset(view)
      @alt_hit = false
      @ctrl_hit = false
      @usertext = ""
      view.invalidate
    end
    
    def onCancel(reason, view)
      reset(view)
    end
    
    def resume(view)
      view.invalidate
    end
    
    def deactivate(view)
      reset(view)
    end
    
    def enableVCB?
      return true
    end
    
    def onUserText(text, view)
      @usertext = text
      view.invalidate
    end

    def onKeyUp(key, rpt, flags, view)
      puts "onKeyUp: key = #{key}"
      if( key == COPY_MODIFIER_KEY )
        # Hack to allow entering ; (list separator) to VCB
        # using Alt Gr on e.g. HU keyboard)
        UI.start_timer(0) { @ctrl_down = false }
        return true if @alt_down
        
        @ctrl_hit = !@ctrl_hit
        view.invalidate
      end
      
      if( key == ALT_MODIFIER_KEY )
        # Hack to allow entering ; (list separator) to VCB
        # using Alt Gr on e.g. HU keyboard)
        UI.start_timer(0) { @alt_down = false }
        return true if @ctrl_down
        
        @alt_hit = !@alt_hit
        view.invalidate
        return true
      end
    end
    
    def onKeyDown(key, rpt, flags, view)
      puts "onKeyDown: key = #{key}"
      if( key == COPY_MODIFIER_KEY )
        @ctrl_down = true
      end
      if( key == ALT_MODIFIER_KEY )
        @alt_down = true
        return true
      end
    end
 
    def draw(view)
      view.draw_text( [10,10], "The current list_separator is #{LIST_SEP}", bold:true ) 
      view.draw_text( [10,30], "Alt hit: #{@alt_hit}", bold:true ) 
      view.draw_text( [10,50], "Ctrl hit: #{@ctrl_hit}", bold:true )
      view.draw_text( [10,80], "VCB value: #{@usertext}", bold:true )
    end
    
  end #DezmoTypeListSeparator class

end #DezmoHackListSeparator
end #Dezmo
Dezmo::DezmoHackListSeparator.run
3 Likes

Hello Dezmo,

in the onKeyDown and onKeyUp events, do you get the same code when you press Alt-Gr (on the right of the keyboard) as Alt (on the left of the keyboard)? I only have Qwerty keyboards.

Fredo

Pressing-releasing Ctrl :
onKeyDown: key = 17
onKeyUp: key = 17

Pressing-releasing Alt :
onKeyDown: key = 18
onKeyUp: key = 18

Pressing-releasing Alt Gr :
onKeyDown: key = 17
onKeyDown: key = 18
onKeyUp: key = 17
onKeyUp: key = 18


Actually Pressing-releasing Alt Gr = Pressing-releasing Ctrl+Alt simultaneously.

I can also enter the ; semicolon by: Ctrl + Alt + , in my Hungarian keyboard in any other Windows program.
It is a Qwerty/Qwertz keyboard.

Thanks. Good to know.
Obviously, we have to detect if there are non-modifier keys between a Down and Up event for Alt, Ctrl and Shift. If so, then we should invalidate the Up event for modifiers.

So, Ctrl+Alt+, would invalidate Ctrl-Up and Alt-Up event (I mean the tool or plugin should ignore them). In most cases, the effect of modifiers is triggered on Up event (i.e. toggle).

Note that the problem already existed with Ctrl-Z and Ctrl-Y.

1 Like