Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!cs.utexas.edu!uwm.edu!mrsvr.UUCP!fish From: fish@gemed.com (Mark Fisher) Newsgroups: comp.unix.i386 Subject: Re: keyboard (re)mapping program? Message-ID: Date: 7 Jun 90 15:59:18 GMT References: <36763@ucbvax.BERKELEY.EDU> Sender: news@mrsvr.UUCP Reply-To: fish@gemed.ge.com (Mark Fisher x4-6553) Organization: GE Medical Systems, Milwaukee, WI Lines: 127 In-reply-to: dma@stat.Berkeley.EDU's message of 5 Jun 90 01:37:31 GMT Here is something that was posted a little while ago. I am posting it again because there might be someone else interested. It is a very annoying problem. From: km@cs.pitt.edu Newsgroups: comp.unix.i386 Subject: capslock/control keys Date: 2 May 90 19:27:24 GMT Reply-To: km@cs.pitt.edu () Organization: Univ. of Pittsburgh Computer Science 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 '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 X#include X#include X#include X#include X#include 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 -- // Mark M. Fisher // fish@gemed.ge.com // uunet!crdgw1!gemed!fish // sun!sunbrew!gemed!fish