-
Avoiding key repeat
I'm executing stuff on keystroke, and I have a little bit of an issue with, if the key is pressed and held, the statements execute over and over again, due to auto-repeat. I've got a workaround which works like this:
Code:
// Keystroke Input
var counter:Number == 0
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
_root.counter += 1;
if _root.counter == 1) {
// Do Stuff;
}
};
keyListener.onKeyUp = function() {
_root.counter = 0;
// Stop Doing Stuff
};
Key.addListener(keyListener);
So, when you press a key, the counter starts ticking up as the keystroke auto-repeats, but "Do Stuff" only happens when you first press it. When you release the key, the counter resets to zero.
It works, but I'm trying to work latency out of the thing, and I think this might be causing some of it. Anyone think of another way to handle it?
-EdM.
-
Senior Member
-
Um, what version is that? I have MX and 8 and neither of them lists that command. I whipped up a sample file using it, and sure enough, it didn't do anything. Did I do it wrong?
Code:
var keyListener:Object = new Object();
keyListener.onKeyPress = function() {
// Do That Thang
};
Key.addListener(keyListener);
I hope I'm being clear-- what I want to be able to do is press and hold a key, but have the specified action happen only once. Currently, since the key auto-repeats, the action happens over and over again.
Just for the sake of clarity, the action is a command from the FlashMIDI plugin, midi.noteOn(channel, pitch, velocity). I'm making a MIDI pitch play when the user hits a key, and stop on the release of that key. The auto-repeat gives the thing a stutter, as the machine thinks the key is being hit over and over again in rapid succession.
-EdM.
Last edited by EdM.; 03-25-2006 at 02:12 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|