Home      Downloads             Documentation      FAQ     

Documentation>ETP-Basic reference>Read the keyboard

 

Read the keyboard


There are two ways to read the calculator's keyboard. Each way has its own advantages.

GetKey( )

The first is the GetKey function. It is a function that waits for the user to press a key and returns the key's value.

Example :

Procedure MAIN:
'The startpoint of your program
Local key as Integer
Do
key = GetKey()
Clear
Locate 10,30,key,4
Loop While key<> 264

This small example allows the user to see the value of each key. We only get outside the Do-While loop when we press [ESC], which has a corresponding value of 264.

GetKey function has some important properties :
  1. The function waits the to user press a key. This can be an advantage, with a simple menu. But with GetKey, it is not possible to continue executing things before the key is pressed.
  2. The [2nd], [SHIFT], [alpha] and [diamond] keys do not return a value. They are like a secondary keyboard. For example, on the TI-89, pressing [alpha] and then [8] gives the letter "h". The returned by Getkey represents "h" and not "8". To sum up, GetKey returns a value of a character, and not of a key.
  3. If you press more than one key, GetKey returns only one value that means nothing. To test several keys, or a key if the user presses several ones, you must use the second way descibed below.


Some properties of GetKey are good, but its use is sometimes not the best (like in games).

Boolean functions (KEY89_LEFT , KEY92_DIAMOND , etc...)

To read the keyboard, you can also use boolean functions (that returns TRUE or FALSE). These functions have the advantage of being very fast and very close to the hardware. When you write :

If KEY89_LEFT Then
Instructions...
EndIf

The calculator will check the physic contact of the conductors under the left arrow key.

This is very fast and has the other advantage to test only one key, even if the user presses more than one.

To test several keys at the same time, it's very simple :

If KEY89_LEFT And KEY89_DIAMOND Then
Instructions...
EndIf

Instructions will be executed if the user presses [LEFT] and [diamond] together.

The matrix of each calculator is different, so you must tell which calculator you want to use. The same program for a TI-92+ or a Voyage 200 will be written :

If KEY92_LEFT And KEY92_DIAMOND Then
Instructions...
EndIf

Using these functions do not set a waiting time. You must set up a loop.

Do
Clear
'make anything you want here...
If KEY89_UP Then
Locate 60,1,"UP",4
EndIf
If KEY89_LEFT Then
Locate 1,40,"LEFT",4
EndIf
If KEY89_RIGHT Then
Locate 100,40,"RIGHT",4
EndIf
If KEY89_2ND Then
Locate 40,20,"2ND",4
EndIf
If KEY89_ENTER Then
Locate 40,60,"ENTER",4
EndIf
Loop While Not (KEY89_ESC)

Here is the list of existing boolean functions :

For TI-89 : For TI92+ and Voyage 200:
KEY89_UP
KEY89_DOWN
KEY89_LEFT
KEY89_RIGHT
KEY89_DIAMOND
KEY89_ALPHA
KEY89_2ND
KEY89_SHIFT
KEY89_ENTER
KEY89_CLEAR
KEY89_ESC
KEY92_UP
KEY92_DOWN
KEY92_LEFT
KEY92_RIGHT
KEY92_DIAMOND
KEY92_ENTER2
KEY92_2ND
KEY92_SHIFT
KEY92_ESC
KEY92_HAND


 

Documentation>ETP-Basic reference>Read the keyboard

     
    About ETP Contact Us