km@cs.pitt.edu (05/03/90)
As follow up to my own question, one CAN use the keymapping ioctl functions for special keys as well as regular keys. The following tiny program can be used to switch two keys. Note that this works for the console and virtual terminals only: under X windows, one can use xmodmap to accomplish the same thing. Ken Mitchum km@cs.pitt.edu #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of shell archive." # Contents: kd.c # Wrapped by km@speedy.cs.pitt.edu on Wed May 2 15:19:32 1990 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'kd.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'kd.c'\" else echo shar: Extracting \"'kd.c'\" \(1663 characters\) sed "s/^X//" >'kd.c' <<'END_OF_FILE' X/* kd.c X Switch two keys by scan code. X Usage: kd key1 key2 X To switch Caps Lock and Left Control Keys: kd 29 58 X To switch accent/tilde and Escape keys: kd 1 41 X Does not work for X windows. X K. Mitchum km@cs.pitt.edu X*/ X#include <sys/types.h> X#include <stdio.h> X#include <fcntl.h> X#include <sys/at_ansi.h> X#include <sys/kd.h> X#include <sys/vt.h> X X Xmain(argc,argv) Xchar *argv[]; X{ X int error,fd, key1, key2; X keymap_t kmap; X struct key_t tmp; X X if(argc != 3) usage(argv[0]); X if(((key1 = atoi(argv[1])) < 0 || key1 >= NUM_KEYS) X || ((key2 = atoi(argv[2])) < 0 || key2 >= NUM_KEYS)) usage(argv[0]); X X if((fd = open("/dev/console",O_RDONLY)) < 0) X perror("Error opening"); X X printf("\nfd = %d",fd); X if((error = ioctl(fd,GIO_KEYMAP,&kmap)) < 0) X perror("Error getting keymap"); X X puten(&tmp,&kmap.key[key1]); X puten(&kmap.key[key1],&kmap.key[key2]); X puten(&kmap.key[key2],&tmp); X X pentry(&(kmap.key[key1]),key1); X pentry(&(kmap.key[key2]),key2); X X if((error = ioctl(fd,PIO_KEYMAP,&kmap)) < 0) X perror("Error setting keymap"); X close(fd); X} X Xputen(dest,src) Xstruct key_t *dest,*src; X{ X int i; X X for(i = 0; i < NUM_STATES; i++) X dest->map[i] = src->map[i]; X dest->spcl = src->spcl; X dest->flgs = src->flgs; X} X Xpentry(en,n) Xstruct key_t *en; X{ X int i; X printf("\nNumber %d %x",n,n); X printf("\nStates: "); X printf("%x ",en->map[0]); X X for(i = 1; i < NUM_STATES; i++) X printf("%x ",en->map[i] ); X printf("\nSpcl %x",en->spcl); X printf("\nFlgs %x", en->flgs); X} X Xusage(pname) Xchar *pname; X{ X fprintf(stderr,"\nUsage: %s key1 key2",pname); X fprintf(stderr,"\nkey1 & key2 are scancodes\n"); X exit(0); X} X END_OF_FILE if test 1663 -ne `wc -c <'kd.c'`; then echo shar: \"'kd.c'\" unpacked with wrong size! fi # end of 'kd.c' fi echo shar: End of shell archive. exit 0