This content has been marked as final. Show 9 replies
Thanks kglad. That seems close. I'll have to try and plug in something like that. At a glance, though, I'm not seeing how that would translate to multiple keys. Would you recommend a separate object for each key to be checked? Otherwise, every time any key was released the repeat var would be set to 0. Or does each key to be checked require its own two variables, such as bolSpaceRepeat and bolSpaceDown? You follow?
Hmmm... just ran a test on that code, and while it works if you quickly press and release the Spacebar, if you hold it down for a moment the Up function isn't triggered. Is this related to the Flash 8 bug/feature I've read about regarding the onKeyUp function?
what's wrong with:
Thanks for working with me on this!
Running your code yields the following problem, which is actually similar to where I got stuck in my own code and came here.
Press and release A key, traces 97
Press and release B key, traces 98
Press and hold A key, then press and hold B key, then release A key and you get... TADA! Nothing! Until you release the B key which then traces 98. Grrr...
Maybe it would be helpful to know what I'm trying to do. I have a guy that moves back and forth controlled by the left and right arrow keys. He throws a ball- but pressing the spacebar increments a power variable, and releasing it throws the ball with the distance determined by the power variable. So... using the code above if you start to "power up" with the spacebar, then start moving left, then release the spacebar- nothing happens.
This process works great with the onMouseDown and onMouseUP, but unfortunately I need to convert this to keyboard for this particular application.
Thanks again for any insight you or anyone else might have!
you aren't going to be able to use key listeners for this because the onKeyDown only detects the most recent key pressed and the onKeyUp only executes when all keys are up (and so can be used to detect the last key released).
you'll need to use a loop that repeatedly checks which keys are pressed. you'll need to track all key presses and use that information to determine when a key is released: ie, it was detected by your loop and then it is not detected.
Sounds unnecessarily complicated, but oh well. Thanks for the help though! I think I can figure that out.
yes, it is going to require storing (say the ascii) value of the keys pressed on each loop and then checking if any of the previously pressed keys are not being pressed.
i think i would use an associative array to track the keys pressed on any given loop. that would make it easy to check on the next loop if those keys are still being pressed and it would make it easy to adjust the array when the key presses change.