Computer Science Canada Input with Input.KeyDown is too fast? |
Author: | NikG [ Mon May 08, 2006 11:37 pm ] | ||
Post subject: | Input with Input.KeyDown is too fast? | ||
Hey all, I got a little problem, demostrated by the sample code below:
What I want is that when the user presses '1' the first time, the value of the variable should change to 'a' and after the 2nd press, it should turn to 'b'. If you uncomment that delay, this works. But I don't want to use a delay of any sort. Although I don't want to do this, I've alse tried adding a boolean that keeps track of keypresses (i.e. if chars ('1') and keydown=false then) but that doesn't work reliably without a delay either. I'm guessing there's no way to do this without a delay. Any ideas? |
Author: | Bobrobyn [ Tue May 09, 2006 7:38 am ] | ||
Post subject: | |||
Try changing your code so that it's not using the same button for the same thing. For example:
|
Author: | jamonathin [ Tue May 09, 2006 9:12 am ] | ||
Post subject: | |||
You could turn it into 2 buttons, or you ca make a fake delay. Basically taking the time when the '1' was pressed and waiting 'x' amount of time until you are allowed to change it again. The 'x' amount in this example is 100. I took out your View.Update because it was unneccesary and slowed things down major.
|
Author: | HellblazerX [ Tue May 09, 2006 4:15 pm ] | ||
Post subject: | |||
actually, I think what NikG is asking for is how do you make it so the user must release the key and press it again to change the value, so the user can't hold down the 1 key and the value will constantly change back and forth. Your original method of using a boolean flag would work nicely in this case:
Note that the pressed condition is in its own separate if construct, otherwise it won't work properly. |
Author: | NikG [ Tue May 09, 2006 9:37 pm ] |
Post subject: | |
Bobrobyn: I need it to be one key, not two. jamonathin: I don't want a delay of any sort. HellblazerX: Thanks, that works, although I was hoping to do it without having to create another variable. Thanks guys. |