AceFORTH allows you to enter information from the
keyboard using INKEY, QUERY and RETYPE. The INKEY
word is the easiest to use as it reads the keyboard and leaves
its ASCII code on the stack, but if you are pressing several keys it leaves 0 on the stack. There are many ways of using the
INKEY word to test for keys pressed, but its only good for reading one character at a time.

QUERY and RETYPE use the input buffer. QUERY clears the input buffer
and then lets you enter characters. RETYTE keeps the characters in the input buffer which gives you a chance to edit them.
More information on these words can be found in the user manual, with the examples.
These AceFORTH
words are useful but for but for some applications - for
example, when combinations of keys must be
read simultaneously - the IN function can be
used to read the keyboard directly.

The keys on the Jupiter Ace are connected to the
Z80 microprocessor through input/output ports.
There are 65536 input/output ports, and each
one can be addressed individually. In the same
way that @ and ! are used to read or write
to memory, IN and OUT are used to read and write
to input/output ports.

The word IN( add - c) will take a port address from the top of the stack (ToS) and
return the value of a port to the ToS, 65278 IN would result with a value from port 65278 on the ToS. while the forth word
OUT( c add -) will write the value c to port add from the stack, 20 65278 OUT
will remove 20 and 65278 from the stack and output the value 20 to port 65278.

The keyboard consists of four rows of 10 keys,
each row being divided into two half-rows of five
keys. Each half-row maps onto a port as shown in the image below, port addresses in blue.

Notice that the keys in the left-hand half-rows
map to their ports from right to left, but that the
right-hand half-rows map left to right.
The rightmost five bits of a port each map onto
a key, and will take the value 0 if the
corresponding key is pressed, or 1 if it is not.

The bits marked X are unspecified (in yellow in the image) - they can hold
either a one or a zero. This means that the value
of left on the stack will be undefined. This problem can be
overcome by setting the value of the top three bits
to zero in software by using 31 AND.

Please note: That on the Ace keyboard the Symbol shift key is next to the SPACE key the above image
is an address port map of where the key ports are mapped.

For example: if the letter c is pressed port 65278 will contain :
XXX11110 = 15

If both SHIFT and the letter c is pressed port 65278 will contain:
XXX01110 = 14 .

If no keys are pressed the value is 31 = XXX11111

Try this demonstration program, keydemo , and press different keys also multiple key presses to see how the port bits change.
The system variable KEYCOD3C26 (15398) is read to EMIT the ASCII code of the last key pressed, note that KEYCOD only stores 1 byte, so multiple key press ASCII codes are not stored.