[comp.sys.atari.st] Keyboard questions?

bob@wiley.UUCP (Bob Amstadt) (10/27/87)

In an attempt to make use of the "Alternate" key, I ran into the
following problem. Its possible for me to type faster than my application
can obtain and deal with the key presses. I would like to detect odd
combinations shift keys, i.e. Control and Alternate, pressed in
combination with a normal key such as a letter. Since I need
to buffer the key presses, the GEMDOS input functions would be
convenient to use, however, they don't allow me to obtain information
about what shift keys were depressed when the key was pressed.
I can't use the BIOS calls because key presses would be lost
(the GEMDOS buffering would steal the keys). Also I do not want
to use a solution that would cause auto repeat not to work.

If anyone knows the answer to the problem, please tell me. I thought
about using GEM, but I noticed that the event for a key pressed also
does not return shift key information. Question to Atari: Why is it
easy to get shift key info when a mouse button is pressed, but not
when a key is pressed?

-- 

		---Bob Amstadt
		bob@wiley.uucp
		{csvax.caltech.edu,uunet.uu.net,trwrb.uucp}!wiley!bob

minow@decvax.UUCP (Martin Minow) (10/29/87)

In article <1516@wiley.UUCP>, Bob Amstadt asks how to read the shift,
control, and alt keys.

Here is a fragment from a much larger program that shows how you
can get this information.  I have no idea how to do this using
the evnt_...(); routines.

Martin Minow
decvax!minow

The following software is in the public domain.  It is incomplete
as it stands and intended only as an illustration.

/*
 * The keytable structure is is returned by Keytbl().  It "points"
 * to the keyboard translation tables in the operating system.
 */

typedef struct {
    char	*unshifted;
    char	*shifted;
    char	*capslock;
} KEYTBL;

#define RIGHTSHIFT	0x01
#define	LEFTSHIFT	0x02
#define CTRLSHIFT	0x04
#define	ALTSHIFT	0x08
#define	CAPSSHIFT	0x10

KEYTBL		*keytbl;

main()
{
	...
	keytbl = Keytbl(-1L, -1L, -1L);	/* keyboard translation table	*/
	...
}
int
read_keyboard()
{
	register long	rawkey;
	register int	scancode;
	register int	c;			/* Translated key code	*/
	register int	shift;

	rawkey = Bconin(2);			/* Get char from kb:	*/
	scancode = (rawkey >> 16) & 0xFF;	/* Raw keyboard code.	*/
	shift = Getshift(-1);			/* Need the ALT key	*/
	if (scancode >= 0x78
	 && scancode <= 0x83)			/* Normalize strange	*/
	    scancode -= (0x78 - 0x02);		/* "ALT" + digit	*/
	if ((c = rawkey & 0xFF) == 0) {		/* ALT compose?		*/
	    if ((shift & (RIGHTSHIFT | LEFTSHIFT)) != 0)
		c = keytbl->shifted[scancode];
	    else if ((shift & CAPSSHIFT) != 0)
		c = keytbl->capslock[scancode];
	    else {
		c = keytbl->unshifted[scancode];
	    }
	    if ((shift & CTRLSHIFT) != 0)
		c &= 0x1F;
	}
	return (c);
}