DEL/BS key on Sun-4 keyboard

Greg Holley sono!holley at sun.com
Thu Jun 15 12:37:31 AEST 1989


I have a Sun 3/60 with a Sun-4 keyboard.   Unlike many recent posters, the
only thing that really bugs me about this keyboard is the nearness of
DELETE and BACKSPACE to each other.  After hitting BS one too many times,
I took the "nolock" routine that appeared a while back in comp.sys.sun,
and rewrote it to change the BS key into a DELETE key (under Unshifted and
CAPS-Lock modes only; the shifted BS key still gives you a ^H).

[Aside:  Does anyone know if the extra keys on the Sun-4 keyboard can be
accessed and reprogrammed?  I'd like to turn the "Help" key into an emacs
info key.]

Greg Holley
sun!sono!holley


Program follows:
------------------------------------------------------------------------
#include <sys/types.h>
#include <sundev/kbd.h>
#include <sundev/kbio.h>
#include <sys/file.h>
#include <stdio.h>

extern int errno;

/* nobs:  Make the BS key the same as the DELETE key in the UNSHIFTED and 
 *	CAPS-LOCK states (it remains a backspace in the SHIFTED and CTRL 
 *	states).  
 *
 *	With no arguments simply checks if the BS key has been reassigned.  
 * 	Arguments "on" and "off" set the BS key to DELETE and BS, 
 *	respectively.
 *
 * 	GLH 12-Jun-89
 *	modification of "nolock", from Usenet comp.sys.sun
*/

#define BS_KEY	0x2b
#define BS_VAL	'\b'
#define DEL_VAL	0x7f

main(argc, argv)
register int argc;
register char **argv;
{
    struct kiockey thekey;
    register int fd, on;
    int type;

    if (argc > 2) {
	fprintf(stderr, "%s: too many args\n", *argv);
	exit(1);
    } else if ((argc==2) && (on=strcmp("on", argv[1])) &&
	strcmp("off", argv[1])) {
	fprintf(stderr, "%s: bad arg (\"%s\")\n", *argv, argv[1]);
	exit(1);
    }
    if ((fd = open("/dev/kbd", O_RDONLY)) == -1) {
	fprintf(stderr, "%s: can't open kbd\n", *argv);
	exit(1);
    }
    if (ioctl(fd, KIOCTYPE, &type) == -1) {
	fprintf(stderr, "%s: can't get kbd type (errno: %d)\n", *argv, errno);
	exit(1);
    }
    if ((type == KB_SUN3)||(type==KB_SUN4) ||
	(type==SUN_2)||(type==KB_KLUNK)) {
	thekey.kio_tablemask = 0;		/* unshifted */
	thekey.kio_station = BS_KEY;		/* Sun-3 Caps Lock key */
	if (argc==1) {
	    if (ioctl(fd, KIOCGETKEY, &thekey) == -1) {
		fprintf(stderr, "%s: bad return from ioctl (%d)\n",
		    argv[0], errno);
		exit(1);
	    }
	    if (thekey.kio_entry == DEL_VAL)
	        prinft("BACKSPACE is DELETE");
	    else
	        printf("BACKSPACE is BACKSPACE");
	    exit(0);
	} else if (!on)
	    thekey.kio_entry = DEL_VAL;
	else
	    thekey.kio_entry = BS_VAL;

	if (ioctl(fd, KIOCSETKEY, &thekey) == -1) {
	    fprintf(stderr, "%s: bad return from ioctl (%d)\n",
		argv[0], errno);
	    exit(1);
	}

	thekey.kio_tablemask = CAPSMASK;	/* caps lock */
	if (ioctl(fd, KIOCSETKEY, &thekey) == -1) {
	    fprintf(stderr, "%s: bad return from ioctl (%d)\n",
		argv[0], errno);
	    exit(1);
	}

    } else {
	fprintf(stderr, "%s: not a SUN-3 keyboard\n", *argv);
	exit(1);
    }
}



More information about the Comp.sys.sun mailing list