KeyDown for only one input
Author |
Message |
GenesisXCS
|
Posted: Tue May 11, 2010 10:55 am Post subject: KeyDown for only one input |
|
|
What is it you are trying to achieve?
I am trying create an input system where I can hold onto a key for as long as I want, but only one output character will show. In order to input two characters, you would need to lift the finger and tap again
I think someone tried to answer this in my last thread, but I guess it is because I am too noob. I think it was the implementation of the REAPEATRATE variable, but again, I am confused and not sure.
What is the problem you are having?
<It may be a problem with my code, but I think in the way that it is set up, it is taking in a few characters at the same time with one tap
Describe what you have tried to solve this problem
<I tried using a "Time.Elapsed" sub-program to check for input every 150 ms or so. I also employed the Input.Flush.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<The program that I am building is a math game using a similar code such as the below> I cannot provide my full program because it uses pictures, and I don't want to submit a sub-par program.
Turing: |
% guess2 = the final answer
% count := 0
Input.KeyDown (char)
if char (chr(48)) then guess := 0
% I would have the same for 0 - 9 %
count := count + 1
if count := 1 then
guess2 := guess
elsif count := 2
then guess2 := guess2 * 10 + guess
elsif count := 3
then guess2 := guess 2 * 10 + guess
end if
|
Please specify what version of Turing you are using
4.1 or// 4.05
Thanks in advance... I am working on it. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
DemonWasp
|
Posted: Tue May 11, 2010 11:08 am Post subject: RE:KeyDown for only one input |
|
|
You will probably want to use polling input (Input.KeyDown) for this, so that you can detect the situation where no keys are pressed (lifting your finger before pressing the same key again).
You want to do something like:
code: |
loop
detect-pressed-keys
if (
( no keys were pressed last time ) or
( key pressed last time is different from key pressed now )
)
then
accept currently-pressed key
end if
exit when input is complete
end loop
|
This will require you to store the set of keys pressed last time through the loop, as well as the current set of keys pressed. You will need to define some scheme for determining priority among the many keys that can be pressed at the same time. You will want to define behaviour for the following types of cases:
1. I press down S, then press down A, then release A, then release S. Do I get SA, AS, SAS, or something else?
2. I press down D, then press down F, then release D, then release F. Do I get DF or FD or something else?
Overall, the best question at this point is: why do you want to do this? What's wrong with standard input methods (like get) that you need to fix? |
|
|
|
|
|
|
|