Menus and key presses: Menu( and getKey
Let the user pick from a menu with Menu( and Lbl, or react to single key presses with a getKey loop.
Menu( shows a title and up to nine choices. Each choice names a label; picking it jumps to the matching Lbl line in the program. Stop ends the program so it does not run into the next label.
getKey gives the code of the last key pressed, or 0 if none was pressed. A Repeat loop that keeps reading getKey waits for a key. Codes are row and column: the 5 key is 83 (row 8, column 3), ENTER is 105.
Classic Graphing 84 · A two-choice menu
Start on the main screen: Press 2nd then mode (QUIT) to get back to the home screen. Pressing clear on a menu also backs out of it.
Create a program called PICK: PRGM, left arrow, 1, then P, I, C, K (8, x², PRGM, ( ) and ENTER.
prgm◀18x²prgm(enterPaste Menu( from PRGM: it is item C of CTL, so press ALPHA, PRGM.
prgmalphaCprgmType the title "PICK", a comma, the first choice "ONE", a comma and its label A. Lock letters for each word and unlock before the commas.
2ndA-LOCKalpha+8x²prgm(+alphaJ,2ndA-LOCKalpha+7logsin+alphaJ,alphaAmathAdd the second choice "TWO" with label B, close the bracket and press ENTER.
,2ndA-LOCKalpha+4−7+alphaJ,alphaBapps)enterLbl A (PRGM, 9, then A), Disp "ONE", and Stop (PRGM, ALPHA, COS for item F).
prgm9alphaAmathenterprgm▶32ndA-LOCKalpha+7logsin+alphaSOLVEenterprgmalphaFcosenterLbl B and Disp "TWO".
prgm9alphaBappsenterprgm▶32ndA-LOCKalpha+4−7+alphaQuit and run it. The menu PICK appears; press 2 to choose TWO.
2ndQUITmodeprgm1enter2
You should seeThe program jumps to Lbl B and shows TWO.
Use the arrow keys and ENTER to pick a choice, or press its number.
Classic Graphing 84 key reference · Classic Graphing 84 manual
Classic Graphing 84 · A getKey loop
Start on the main screen: Press 2nd then mode (QUIT) to get back to the home screen. Pressing clear on a menu also backs out of it.
Create a program called KEY: PRGM, left arrow, 1, then K, E, Y (the (, SIN and 1 keys) and ENTER.
prgm◀1(sin1enterLine 1, 0→K, so the loop starts with no key.
0sto→alphaK(enterLine 2, Repeat K: PRGM, 6, then K. The loop repeats until K is not 0.
prgm6alphaK(enterLine 3, getKey→K: PRGM, right arrow, 6 (getKey), STO→, K.
prgm▶6sto→alphaK(enterLine 4, End, and line 5, Disp K.
prgm7enterprgm▶3alphaK(Quit and run it. The busy marker shows while it waits; press the 5 key.
2ndQUITmodeprgm1enter5
You should seeThe key code of 5, 83, is shown.
Press ON to break out of a loop that never ends.
Classic Graphing 84 key reference · Classic Graphing 84 manual
Tips
- Arrow key codes are 24 (left), 25 (up), 26 (right) and 34 (down). Games use them to move a character with Output(.
- Every label named in Menu( must exist in the program, or you get ERR:LABEL.
Related guides
- Make decisions with If, Then and ElseWrite a program that tells you whether a number is negative, using If, Then, Else and End.
- Repeat steps with a For loopAdd the whole numbers from 1 to 100 with For( and End, and show the total 5050.
- Programs on the Classic Graphing 84Where programs live on the Classic Graphing 84, and how to create, edit, run and stop them.