Section 1.7---The getKey command
Section 1.7---The getKey command

Back to home

The getKey command is a command that gets a keypress and stores the information to a variable. This is useful if you have interactive graphics, or many other things. The command looks like this:
:getKey->D

First, you need to know how the keyboard is mapped out. The tens go from the top row down, starting with 10 and ending with 100. Ones go across to the right, and start with 1 (not 0!), and end with 5. It may be a little confusing, but here are some examples:
Y= (11).....Graph (15).....Enter (105).....2nd (21).....Alpha (31).....Apps (42)
So, find the coordinates of the Math key. You should have gotten 41. Next, try to find the coordinates of the 1 key. It should be 92. There are five exceptions to this:
The On key (You can't use this during a program or else it breaks it. This has no mapping).....Left Arrow (24).....Up Arrow (25).....Right Arrow (26).....Down Arrow (34)
However, getKey doesn't wait for you to press a key. If you don't have a key pressed, it skips over everything. So, how do you have it wait until you press a key? (Note, sometimes you don't want to do this, so just leave out the following lines of code).
:0->D
:While D=0
:getKey->D
:End
And here you go on to...
:If D=24
:BlahBlahBlah...

The
Key
Program
This next program that you should write should clear the homescreen, wait for the user to press a key, and then tell what they key is. You don't have to map out all the keys on the keyboard, just popular ones like 2nd and Arrow Keys. A copy of the code is found below.

Here's the code to the Key program.
:ClrHome
:0->D
:While D=0
:getKey->D
:End
:If D=21
:Disp "2nd"
:If D=31
:Disp "Alpha"
:If D=24
:Disp "Left Arrow"
And so on

This will be the end of section 1. Try programming a bit to get a feel for the commands. Remember, the best way to learn this stuff is to experiment!

Section 2.1--Lbls and Gotos