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

      I've not used that parameter before. But I do see the same. 😞

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

      1 Reply Last reply Reply Quote 0
      • Chris FullmerC Offline
        Chris Fullmer
        last edited by

        That API states:

        @unknownuser said:

        V6: There is a bug on Windows where the typematic effect does not work. Typematic effects work fine on a Mac.

        http://code.google.com/apis/sketchup/docs/ourdoc/tool.html#onKeyDown

        I guess it has not been fixed for v7 or 7.1 too then?

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

        1 Reply Last reply Reply Quote 0
        • tbdT Offline
          tbd
          last edited by

          seems that is stuck in v7 as well. not good.

          I plan to make SU Ruby API page that contains all of our findings, code snippets and examples using the searchable interface from Rails API as I am wasting too much time with current google's implementation (due page jumping and incorrect data)

          SketchUp Ruby Consultant | Podium 1.x developer
          http://plugins.ro

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

            @unknownuser said:

            seems that is stuck in v7 as well. not good.

            I plan to make SU Ruby API page that contains all of our findings, code snippets and examples using the searchable interface from Rails API as I am wasting too much time with current google's implementation (due page jumping and incorrect data)

            Any way to contribute? Got lots of into in this thread: http://forums.sketchucation.com/viewtopic.php?f=180&t=17047

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

            1 Reply Last reply Reply Quote 0
            • tbdT Offline
              tbd
              last edited by

              I plan to have it on github/bitbucket and also a web module for those that want to contribute and don't want to get 'dirty' with version control systems.

              There will be also a downloadable version for speed maniacs like me πŸ˜‰

              and that thread is the first on my list of sources. thanks for work involved.

              SketchUp Ruby Consultant | Podium 1.x developer
              http://plugins.ro

              1 Reply Last reply Reply Quote 0
              • TIGT Offline
                TIG Moderator
                last edited by

                Wouldn't a temporary 'fix' be [without the need for other perhaps platform specific solutions], to ask the user to keep rapidly pressing a certain modifier key [key-down/key-up] - that way you can check for keyDown and keyUp actions, and then you'd know what they are doing: the final keyUp would exit after a set short-time without a keyDown occuring ?
                Exactly why do you [we] need this specific action anyway ❓

                TIG

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

                  @tig said:

                  Wouldn't a temporary 'fix' be [without the need for other perhaps platform specific solutions], to ask the user to keep rapidly pressing a certain modifier key [key-down/key-up] - that way you can check for keyDown and keyUp actions, and then you'd know what they are doing: the final keyUp would exit after a set short-time without a keyDown occuring ?
                  Exactly why do you [we] need this specific action anyway ❓

                  Or use a timer that starts on keydown and stop on keyup - accounting for the initial delay for the repeating to trigger. And I think the repeat interval isn't linear...

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

                  1 Reply Last reply Reply Quote 0
                  • tbdT Offline
                    tbd
                    last edited by

                    @tig said:

                    Exactly why do you [we] need this specific action anyway

                    I plan to use it for a tool to increase/decrease radius of tool action based on VK_UP/DOWN press. on Mac it works great, on Windows you need to press,release,press,release - it kills the fun πŸ˜‰

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

                    SketchUp Ruby Consultant | Podium 1.x developer
                    http://plugins.ro

                    1 Reply Last reply Reply Quote 0
                    • 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