sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    OnKeyDown repeat parameter problem

    Scheduled Pinned Locked Moved Developers' Forum
    21 Posts 8 Posters 4.2k Views 8 Watching
    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.
    • thomthomT Offline
      thomthom
      last edited by

      @unknownuser said:

      I should try the timer solution and see the correct 'amount' of delay for a typematic effect πŸ˜‰

      Think the system default is stored in the registry somewhere. If you want to try to match that.

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

      1 Reply Last reply Reply Quote 0
      • M Offline
        mtalbott
        last edited by

        TBD,

        Were you, or anyone else, able to create a good work-around for the repeat bugg on windows? I was wondering myself how best to set a timer to determine a key being held down.

        I am using this on a fun script that makes navigating a model more like a FPS.

        -Mike

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

          There's an issue with SU's timers - the interval is rounded down to whole integers. So anything below 1.0 will turn into 0.0 turning the timer into an instant loop.

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

          1 Reply Last reply Reply Quote 0
          • M Offline
            mtalbott
            last edited by

            Thanks ThomThom,

            That's good to know. So I'm still lost to how to create a key holding function on windows. I was hoping to be able to start a loop on the onKeyDown and then have onKeyUp break the loop. Unfortunately, once the loops starts sketchup seems to be too busy working on that to notice that I've released the key. Any ideas on how to break the onKeyDown loop when a key is released?

            -Mike

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

              hm.. well, using a timer might work. Even though its bugged. It might just be that it allow other stuff to execute before it restart the iteration. ??

              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

                @mtalbott said:

                Any ideas on how to break the onKeyDown loop when a key is released?
                -Mike
                Perhaps:

                (1) Try executing the onKeyDown loop in a subthread, so that the main thread can still 'trap' the onKeyUp event. You would probably need your Tool to have an boolean instance var, like @mykeydown, set to true by the onKeyDown event callback method, BEFORE you go into the loop; and for example the loop condition might be:
                while @mykeydown do ...[code]... end
                ..then the onKeyUp event callback method would set @mykeydown=false, and the loop should exit on the next pass.
                The big trickis that you need the call to yourTool.onKeyDown to return (while still running the loop in a sub-thread,) so Sketchup can do other things, including redraw the UI, and watch for the release of the keys, so it can call the yourTool.onKeyUp method.

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • M Offline
                  mtalbott
                  last edited by

                  @unknownuser said:

                  big trick is that you need the call to yourTool.onKeyDown to return (while still running the loop in a sub-thread,)

                  That's great advice. I was missing that big trick part. I think I inadvertenly figured that out but in a slightly different way. I was having trouble getting the view to refreash so I ending up having the onKeyDown create an animation object which contained the main loop in the Nextframe def. To my suprise, it worked! I used the onKeyUp to cancel out the animation object.

                  I've attached the plugin if anyone is interested. It's just a different way to walk around a model. more like a video game. I find the walk tool hard to use and pan/orbit is great for modeling but it's not as emersive as a video game style navigation.

                  controls are:
                  keypad to walk forward/back, step left/right.
                  move mouse to look around/ turn.
                  Ctrl to jump (just for fun).
                  esc to reset it if it gets all messed up (which sometimes it does)
                  select another tool to exit

                  This is only my thrid script that I've mostly completed so I apologize for what is probably terrible coding. there are definately a few bugs in it but this is about as far as my skills can get me.

                  The major remaining issue with no solution I can think of is that in a videogame you can just move the mouse endlessly to the left and right to turn. Unfortunately, In sketchup you have limited screen space to move the mouse in. If there was a way to get around that, I'll be really excited about this plugin.

                  Thanks again for the help. This is a great community,
                  Mike


                  First Person "Sketchuper"

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

                    @mtalbott said:

                    The major remaining issue with no solution I can think of is that in a videogame you can just move the mouse endlessly to the left and right to turn. Unfortunately, In sketchup you have limited screen space to move the mouse in. If there was a way to get around that, I'll be really excited about this plugin.

                    (1) What about trapping the left and right mouse buttons to turn, rather than moving the mouse?

                    (2) When I think of video games (the only one I play,) I think of MS Flight Simulator. This plugin would be great for my MS FlightStick. Left, right, forward and back on the stick moves. Twist (rudder left/right,) would pivot. And the rocker switch (often used for elevator/pitch trim,) would be up and down, for going up and down stairs. Other buttons could do other things such as interact with Dynamic Components (like open a door.) Would need to figure out how to write a Ruby binding to the USB game controller interface.

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • renderizaR Offline
                      renderiza
                      last edited by

                      @dan rathbun said:

                      @mtalbott said:

                      Any ideas on how to break the onKeyDown loop when a key is released?
                      -Mike
                      Perhaps:

                      (1) Try executing the onKeyDown loop in a subthread, so that the main thread can still 'trap' the onKeyUp event. You would probably need your Tool to have an boolean instance var, like @mykeydown, set to true by the onKeyDown event callback method, BEFORE you go into the loop; and for example the loop condition might be:
                      while @mykeydown do ...[code]... end
                      ..then the onKeyUp event callback method would set @mykeydown=false, and the loop should exit on the next pass.
                      The big trickis that you need the call to yourTool.onKeyDown to return (while still running the loop in a sub-thread,) so Sketchup can do other things, including redraw the UI, and watch for the release of the keys, so it can call the yourTool.onKeyUp method.

                      Can someone explain this with an example code so I can understand better. What is a subthread? I can't figure out how to solve this "Typematic effects" bug in windows. Please Help

                      [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

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

                        Well threads do not work well in embedded Ruby.

                        Use a UI.start_timer block, which may create a native thread on the C++ side of the SketchUp engine.

                        I'm not here much anymore.

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

                          @dan rathbun said:

                          Use a UI.start_timer block, which may create a native thread on the C++ side of the SketchUp engine.

                          It doesn't create a thread. If the timer block do a lot of time consuming things it blocks everything else until it's done.

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

                          1 Reply Last reply Reply Quote 0
                          • fredo6F Offline
                            fredo6
                            last edited by

                            To simulate typematics, it is preferable to use the animation API.
                            Tricky, but works fine in the end (I used it in ThruPaint)

                            Fredo

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

                            Advertisement