开发者

How to use the arrow keys in a custom TI program

开发者 https://www.devze.com 2023-03-25 11:49 出处:网络
开发者_JAVA技巧I have looked at as many functions as I can and I still can\'t find one that lets you intercept the click of a TI arrow key click.For Basic programs, which are run with the \"Prog\" but

开发者_JAVA技巧I have looked at as many functions as I can and I still can't find one that lets you intercept the click of a TI arrow key click.


For Basic programs, which are run with the "Prog" button, you'll need to call getKey, which returns a key code for the last button pressed. The arrow buttons are mapped to codes 24, 25, 26, and 34.

More information is available at TI-Basic Developer, underneath the heading "Reading Keypresses".


I know this is an old question, but I think this point might still be relevant.

If you are using the key input to move a character, or shift a value somehow, you are almost always better off avoiding if-then-else statements.

The fastest method is usually to do something like this:

:getkey -> A
:X+(A=24) -> X
:X-(A=26) -> X
:Y+(A=25) -> Y
:Y-(A=34) -> Y

which can be further condensed to:

:getkey -> A
:X+(A=24)-(A=26) -> X
:Y+(A=25)-(A=34) -> Y

Instead of dealing with the logic through the if statements, we utilize the fact that the (A=24) has a 'boolean' (0 or 1) value. So we add or subtract 1 if it is a certain value.

Setting limits is also fairly easy:

:getkey -> A
:X+(A=26)(X<=20)-(A=24)(X>0) -> X
:Y+(A=25)(Y<=15)-(A=34)(Y>=3) -> Y

So if (X<20) it will multiply by 1, but when X>=20, (X<20) will multiply by 0, negating the incriment.

I use another technique to help with selecting values in some of my programs: The left and right keys increment and decrement a variable by a different value than the up and down keys do. However, it requires some more logic.

:getkey -> A
:X+10(A=26)(X+10<=100)-10(A=24)(X-10>=0) -> X
:Y+(A=25)(Y<15)-(A=34)(Y>3) -> B

In this case, the left and right arrows go by tens, and the up and down go by ones. (X+10<=100) is used instead of (X<100) because the latter will be true if X=99 so X can go up to 109. The former makes sure that adding ten will not exceed the limit.


You should be able to do it with the getkey command.

getkey (Store as) (Variable) A
while A=0
getkey (Store as) A

Then you can recall the variable A throughout the program. Each key has a number that is called through the getkey command. So you can use that variable by,

If A = 25
...
If A != 25
...

(25 would be the up arrow)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号