Omnimaga
Calculator Community => TI Calculators => Axe => Topic started by: leafy on February 10, 2011, 03:10:00 pm
-
It's not really an issue, I just don't know how to program this:
So I have in my program
If getkey(54)
...
End
But it keeps repeating. That's not what I want. I want it to act like
getKey-->K
If K=54
...
End
But using this method you can't press multiple keys at a time.
So how do I use the first method, but tell it to stop repeating if a key is held?
-
getKey(54)
Ans*(Ans≠K)
If Ans
Then
Ans→K
<<More code>>
End
That is the best I can think of, sorry.
-
if it keeps repeating, it is probably due to a loop being activated before the code, or a Goto statement causing an infinite loop. Something like this always works:
Repeat GetKey(15)
If GetKey(54)
Disp "Daddy would you like some sausage :)", i
End:End
what is probably wrong with your code is an unexpected loop earlier, I'm sure. I would look at the code right above and below the If and the End of the getkey statement.
-
What I do, is store 0 to K, and then at the start of a Repeat loop or whatever, the first line is "If K=0:GetKey->K:End". That way, as long as K has some value, it makes sure you read it before it checks any other keys. And to acknowledge you read it, just write 0 to K. This works because it won't read getkey again until you tell it to. It has the added benefit of letting you decide if the users should be able to press the key again, or shouldn't be able to press keys. Like storing 1 to K automatically disables key presses. Or if you want, you can make the person continue to go right for 5 steps, but keeping a counter, and storing 0 to K when the counter is up.
-
Okay, I fixed it.
What I did was set K to 0, then
!If getKey(54)
1->K
End
If getKey(54) and (K=1)
0->K
...
End
-
Alternatively, you can use this piece of code and eliminate one of the getKeys()
If getKey(54)
If K
...
End
0->K
Else
1->K
End
-
This is what I use. It's probably horribly inefficient though:
If getKey(54)
While getKey(54)
End
<stuff here>
End
-
0->A
.Some sort of loop
If A
... Stuff that should only be run w/o repeat
End
...stuff with repeat
getKey=0->A
.end loop
This could be a relatively efficient solution.
-
If you want to detect multiple keys, you could take advantage of bitwise operations.
Example:
not(K) and (getKey(1)*2+getKey(2)*2+getKey(3)*2+getKey(4)->K)->N
K holds the bitfield of raw key states, N holds the bitfield of any newly pressed keys since the last detection. You can then extract the bits using normal methods, of course. This way you can use just two variables to handle up to 16 keys (keep in mind that if you use more than 8 keys, you'll have to use the 16-bit versions of the bitwise operators)
Edit: formatting