sketchucation logo sketchucation
    • Login
    ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

    Disable OnLButtonUp when onLButtonDoubleClick

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 4 Posters 770 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C Offline
      c.plassais
      last edited by

      Hi,

      In class Tool, Is it possible to disable the method OnLButtonUp or OnLButtonDown when you call the method onLButtonDoubleClick

      Thank you in advance for your answers

      ChrisP

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        I do not think so. You can use a timer to defer execution for a fraction of a second, and then a DoubleClick can cancel the timer.

        Hi

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          @jim said:

          I do not think so. You can use a timer to defer execution for a fraction of a second, and then a DoubleClick can cancel the timer.

          Will only work on SU8 or later as the timer in previous versions was bugged, rounding everything down - the minimum you could defer would be a second in them versions.

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            What is order of UI::Tool class callbacks called by Sketchup, when a user double clicks the Left Mouse Button, including onKeyDown() and onKeyUP() ?

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • J Offline
              Jim
              last edited by

              Seems LButtonDown and LButtonUp always and only occur once each, followed by onLButtonDoubleClick if there was an one.

              Here's the double-click output from the script below:

              ` onLButtonDown
              onLButtonUp
              onLButtonDoubleClick


              -------------------------`

              
              class TestTool
                  def onKeyUp key, repeat, flags, view
                      puts ;onKeyUp
                      add_newline(Time.now)
                  end
                  def onKeyDown key, repeat, flags, view
                      puts ;onKeyDown
                      add_newline(Time.now)
                  end
                  def onLButtonDoubleClick flags, x, y, view
                      puts ;onLButtonDoubleClick
                      add_newline(Time.now)
                  end
                  def onLButtonDown flags, x, y, view
                      puts ;onLButtonDown
                      add_newline(Time.now)
                  end
                  def onLButtonUp flags, x, y, view
                      puts ;onLButtonUp
                      add_newline(Time.now)
                  end
                  def add_newline(t)
                      UI.start_timer(1) { puts "-" * 25 }
                  end
              end
              
              Sketchup.active_model.select_tool TestTool.new
              
              

              Hi

              1 Reply Last reply Reply Quote 0
              • C Offline
                c.plassais
                last edited by

                Dan is to prohibit the use of onKeyDown ()and onkeyup ()when a user double clicks the Left Mouse Button.

                As Jim says, the solution is perhaps to calculate the delay between two onKeyUp (), if the delay is small consider that a double click to invoke a method equivalent onLButtonDoubleClick. if not call the method onKeyUp () and / or onKeyDown ()

                1 Reply Last reply Reply Quote 0
                • C Offline
                  c.plassais
                  last edited by

                  Thanks Jim

                  What do you think about this

                  class TestTool
                      def onLButtonDown flags, x, y, view
                          puts "-" *25
                          puts ;onLButtonDown
                          @id = UI.start_timer(1,false){call_method(flags ="single", x, y, view)}  
                      end
                      def onLButtonUp flags, x, y, view
                          puts ;onLButtonUp
                      end
                  
                      def onLButtonDoubleClick flags, x, y, view
                          UI.stop_timer @id
                          puts ;onLButtonDoubleClick
                         call_method(flags ="double", x, y, view)
                      end     
                      def call_method(flags, x, y, view)
                          if flags == "single"
                              UI.stop_timer @id            
                              puts "Call method for onLButtonDown"
                              puts "Call method for onLButtonUp"
                          else
                              puts "Call method for onLButtonDoubleClick"
                          end
                          puts "-" *25
                      end
                  end
                  
                  Sketchup.active_model.select_tool TestTool.new
                  

                  should be able to reduce the UI.start_timerto less than 1 second....

                  1 Reply Last reply Reply Quote 0
                  • C Offline
                    c.plassais
                    last edited by

                    It works, you can use onLButtonDoubleClick without calling onLButtonDown & onLButtonUp
                    The delay time is 0.2 it works well for me but it is possible that changes depending on the computer

                    For SU8

                    class TestTool
                    
                        def onLButtonDown(flags, x, y, view)
                            puts "-" *25
                            puts ;onLButtonDown
                            @ip = UI.start_timer(0.2,false){call_method(flags, x, y, view)}   
                        end
                        def onLButtonUp(flags, x, y, view)
                            puts ;onLButtonUp
                        end
                    
                        def onLButtonDoubleClick(flags, x, y, view)
                            UI.stop_timer @ip
                            puts ;onLButtonDoubleClick
                            puts "Call method for onLButtonDoubleClick"
                            puts "-" *25
                    
                        end     
                        def call_method(flags, x, y, view)
                                puts "Call method for onLButtonDown"
                                puts "Call method for onLButtonUp"
                            puts "-" *25
                        end
                    end
                    
                    Sketchup.active_model.select_tool TestTool.new
                    

                    For SU6 & SU7

                    class TestTool
                        def onLButtonDown(flags, x, y, view)
                            puts ;onLButtonDown 							# for test      
                            call_method(flags, x, y, view)
                        end
                        def onLButtonUp flags, x, y, view
                            puts ;onLButtonUp							# for test
                        end
                        def onLButtonDoubleClick(flags, x, y, view)
                            UI.stop_timer @id
                            puts ;onLButtonDoubleClick						# for test
                            puts "Call method onLButtonDoubleClick"					# for test
                            puts "-" * 25 								# for test       
                        end     
                        def call_method(flags, x, y, view)
                                start_time = Time.now
                                elapsed_time = 0
                              	loop do
                                       elapsed_time = Time.now - start_time                         # for test
                                       puts elapsed_time     
                                      	if elapsed_time >= 0.20   				###### delay time ######
                                                    @id = UI.start_timer(0,false){
                            			puts "Call similar method for onLButtonDown"
                                        		puts "Call similar method for onLButtonUp"
                                        		puts "-" * 25					# for test
                                        		}                  
                                        	break
                                      	end
                              	end    
                        end
                    end
                    
                    Sketchup.active_model.select_tool TestTool.new
                    
                    
                    

                    ChrisP

                    1 Reply Last reply Reply Quote 0
                    • thomthomT Offline
                      thomthom
                      last edited by

                      @c.plassais said:

                      The delay time is 0.2 it works well for me but it is possible that changes depending on the computer

                      Under Windows this can be configured by the user. Registry setting. Expect one can set it under OSX - but I have no idea where you'd get the setting.

                      Thomas Thomassen — SketchUp Monkey & Coding addict
                      List of my plugins and link to the CookieWare fund

                      1 Reply Last reply Reply Quote 0
                      • C Offline
                        c.plassais
                        last edited by

                        In the script, it's just the time allowed to detect the double click

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement