kimcm@olamb.UUCP (Kim Chr. Madsen) (10/13/86)
Here is a nice little program for finding out what codes each key on the keyboard is sending to the system - it is especially handy trying to find out what some function-keys are sending. The program is developed under UNIX system V on a 3B2/400. #!/bin/sh # shar: Shell Archiver # Run the following text with /bin/sh to create: # ascii.h # code.c sed 's/^X//' << 'SHAR_EOF' > ascii.h X/* X * Defines special characters and their values. X * X * (c) 1986 by Kim Chr. Madsen at AmbraSoft A/S. X */ X X#define NUL 000 X#define SOH 001 X#define STX 002 X#define ETX 003 X#define EOT 004 X#define ENQ 005 X#define ACK 006 X#define BEL 007 X#define BS 010 X#define HT 011 X#define LF 012 X#define VT 013 X#define FF 014 X#define CR 015 X#define SO 016 X#define SI 017 X#define DLE 020 X#define DC1 021 X#define DC2 022 X#define DC3 023 X#define DC4 024 X#define NAK 025 X#define SYN 026 X#define ETB 027 X#define CAN 030 X#define EM 031 X#define SUB 032 X#define ESC 033 X#define FS 034 X#define GS 035 X#define RS 036 X#define US 037 X#define SP 040 X#define DEL 0177 SHAR_EOF sed 's/^X//' << 'SHAR_EOF' > code.c X/* X * code - a program to determine the numerical codes for keys on the X * keyboard. X * X * call: X * code X * X * instructions: X * Call code, and you will get the prompt ``code> '' X * enter the key and and you will see the numerical X * codes in decimal, octal and hexadecimal. X * Enter DEL twice to escape the program. X * X * (c) 1986 by Kim Chr. Madsen @ AmbraSoft A/S X * kimcm@olamb.UUCP or ..seismo!mcvax!diku!olamb!kimcm X * X */ X X#include <stdio.h> X#include <sys/types.h> X#include <termio.h> X#include <sys/ioctl.h> X#include "ascii.h" X Xstruct termio tty, ntty; X Xmain(argc, argv) Xint argc; Xchar *argv[]; X{ X char *prompt = "code> "; X char c; X int pos; X int del=0; X X if (ioctl(0, TCGETA, &tty)) { X perror("ioctl"); X exit(1); X } X ntty = tty; X ntty.c_iflag &= ~IXON; X ntty.c_iflag &= ~IXOFF; X ntty.c_lflag &= ~ISIG; X ntty.c_lflag &= ~ICANON; X ntty.c_lflag &= ~ECHO; X ntty.c_oflag &= ~OPOST; X ntty.c_cc[VTIME] = 30; X ntty.c_cc[VMIN] = 1; X ioctl(0, TCSETA, &ntty); X printf(prompt); X pos=3; X for (;;) { X c=getchar(); X switch (c) { X case NUL : X printf("<NUL>"); X break; X case SOH : X printf("<SOH>"); X break; X case STX : X printf("<STX>"); X break; X case ETX : X printf("<ETX>"); X break; X case EOT : X printf("<EOT>"); X break; X case ENQ : X printf("<ENQ>"); X break; X case ACK : X printf("<ACK>"); X break; X case BEL : X printf("<BEL>"); X break; X case BS : X printf("<BS> "); X break; X case HT : X printf("<HT> "); X break; X case LF : X printf("<LF> "); X break; X case VT : X printf("<VT> "); X break; X case FF : X printf("<FF> "); X break; X case CR : X printf("<CR> "); X break; X case SO : X printf("<SO> "); X break; X case SI : X printf("<SI> "); X break; X case DLE : X printf("<DLE>"); X break; X case DC1 : X printf("<DC1>"); X break; X case DC2 : X printf("<DC2>"); X break; X case DC3 : X printf("<DC3>"); X break; X case DC4 : X printf("<DC4>"); X break; X case NAK : X printf("<NAK>"); X break; X case SYN : X printf("<SYN>"); X break; X case ETB : X printf("<ETB>"); X break; X case CAN : X printf("<CAN>"); X break; X case EM : X printf("<EM> "); X break; X case SUB : X printf("<SUB>"); X break; X case ESC : X printf("<ESC>"); X break; X case FS : X printf("<FS> "); X break; X case GS : X printf("<GS> "); X break; X case RS : X printf("<RS> "); X break; X case US : X printf("<US> "); X break; X case SP : X printf("<SP> "); X break; X case DEL : X if (del) goto end; X del++; X printf("<DEL>"); X break; X default : X printf("%c ",c); X break; X } X printf(" %4d 0%-4o 0x%-4x\n\r%s",c,c,c,prompt); X if (c != DEL) del=0; X } Xend: printf("\n\r"); X ioctl(0, TCSETA, &tty); X} SHAR_EOF exit