[comp.sys.atari.st] Help : hex for keys and screen

keithr@vice.ICO.TEK.COM (U.D.M.) (03/09/91)

I was wondering where I might find the hex code for the keys on the
ST keyboard (arrows keys, functions keys) and special screen
characters (arrows, bells, etc).  Any help would be greatly
appreciated.

Thanks

Keith Rast
keithr@icogem3.ICO.TEK.COM

steve@thelake.mn.org (Steve Yelvington) (03/09/91)

[In article <7077@vice.ICO.TEK.COM>,
     keithr@vice.ICO.TEK.COM (U.D.M.) writes ... ]

> I was wondering where I might find the hex code for the keys on the
> ST keyboard (arrows keys, functions keys) and special screen
> characters (arrows, bells, etc).  Any help would be greatly
> appreciated.

The BIOS Bcon* and GEMdos Ccon* functions return 32-bit values.
Since the ST is natively a 16-bit machine, 32-bit values are
difficult to work with. (For example, a switch-case statement in
C expects 16-bit quantities with most C compilers.) Fortunately,
most of the data encoded in the 32-bit returned value is of little
or no use. By shifting bits, you can ``collapse'' the useful data into
16 bits quite easily.

The source code to the dLibs getch() function shows how to do this.
The function returns the ASCII value in the low byte and a scan
code in the high byte.

Scan codes are unique for each key, and each alt/control/etc. key
combination. This makes it possible to distinguish between the 4 on 
the numeric keypad and the 4 on the typewriter keypad, for example.

Some keys, such as the cursor arrows, function keys, HELP, UNDO,
etc., do not produce ASCII values. In their cases, the low byte
will be null and only the high byte is useful.

Various ST reference books contain tables of key values, but
you can easily produce your own by writing a small program that
prompts you for a key definition, followed by the keystroke. You
can even write the output to a keydefs.h file if you like.

Here are some useful codes (not all of them, though):

/*
 * Atari ST 16-bit function key values
 * for use with getch()
 */

#define ARROW_LEFT	0x4B00		/* [left arrow] */
#define ARROW_RIGHT	0x4D00		/* [right arrow]*/
#define ARROW_UP	0x4800		/* [up arrow] 	*/
#define ARROW_DOWN	0x5000		/* [down arrow] */
#define KEY_TAB		0x0F09		/* [tab]	*/
#define	KEY_UNDO	0x6100		/* [undo]	*/
#define	KEY_HELP	0x6200		/* [help]	*/
#define	KEY_INS		0x5200		/* [insert]	*/
#define	KEY_CLR		0x4700		/* [clr/home]	*/
#define	KEY_CR		0x1C0D		/* [return]	*/
#define	KEY_ENTER	0x720D		/* [enter]	*/
#define	KEY_LF		0x720D		/* [enter]	*/
#define	KEY_BS		0x0E08		/* [backspace]	*/
#define	KEY_DEL		0x537F		/* [delete]	*/
#define	KEY_BRK		0x2E03		/* [control][C]	*/
#define	KEY_F1		0x3B00		/* [f1]		*/
#define	KEY_F2		0x3C00		/* [f2]		*/
#define	KEY_F3		0x3D00		/* [f3]		*/
#define	KEY_F4		0x3E00		/* [f4]		*/
#define	KEY_F5		0x3F00		/* [f5]		*/
#define	KEY_F6		0x4000		/* [f6]		*/
#define	KEY_F7		0x4100		/* [f7]		*/
#define	KEY_F8		0x4200		/* [f8]		*/
#define	KEY_F9		0x4300		/* [f9]		*/
#define	KEY_F10		0x4400		/* [f10]	*/
#define	ALT_DASH	0x8200		/* [alt][-]	*/
#define	ALT_A		0x1E00		/* [alt][A]	*/
#define	ALT_B		0x3000		/* [alt][B]	*/
#define	ALT_C		0x2E00		/* [alt][C]	*/
#define ALT_D		0x2000
#define	ALT_E		0x1200		/* [alt][E]	*/
#define	ALT_F		0x2100		/* [alt][F]	*/
#define	ALT_H		0x2300		/* [alt][H]	*/
#define ALT_I		0x1700
#define ALT_J		0x2400
#define ALT_K		0x2500
#define	ALT_R		0x1300		/* [alt][R]	*/
#define	ALT_S		0x1F00		/* [alt][S]	*/
#define	ALT_T		0x1400		/* [alt][T]	*/
#define	ALT_0		0x8100		/* [alt][0]	*/
#define	ALT_X		0x2D00		/* [alt][X]	*/
#define	ALT_G		0x2200		/* [alt][G]	*/
#define ALT_P		0x1900		/* [alt][P]	*/
#define ALT_L		0x2600		/* [alt][L]	*/
#define	ALT_V		0x2F00		/* [alt][V]	*/
#define KEY_ESCAPE	0x011B
----
  Steve Yelvington / P. O. Box 38 / Marine on St. Croix, MN 55047 USA
  INTERNET: steve@thelake.mn.org    UUCP: plains!umn-cs!thelake!steve