OnKeyDown repeat parameter problem
-
@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 anywayOr 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...
-
@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
-
@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.
-
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
-
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.
-
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
-
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. ??
-
@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. -
@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 exitThis 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
-
@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.
-
@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
-
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. -
@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.
-
To simulate typematics, it is preferable to use the animation API.
Tricky, but works fine in the end (I used it in ThruPaint)Fredo
Advertisement