An ioctl question
Roger Bannister
bann at virgin.UUCP
Thu Oct 26 07:18:08 AEST 1989
I modified this progam that I found in a book so that prints out
the hex code of each key. I noticed that the keypad was producing the
same scan codes as the regular keys. Is there a way to get the keypad
to give different scan code like curses.
Roger
---------------------Program Starts here ----------------------------------
#include <sys/ioctl.h>
#include <sys/termio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <time.h>
#include <stdio.h>
#define CLRSCR printf("\033[2J")
struct termio OLD, NEW;
int Keyfile;
InitKeyboard()
{
Keyfile = open("/dev/tty",O_RDONLY);
if (Keyfile < 0)
{
printf("Unable to open /dev/tty\n");
exit(1);
}
ioctl(Keyfile, TCGETA, &OLD);
}
SetRead()
{
NEW.c_lflag &= ~ICANON;
NEW.c_lflag &= ~ECHO;
NEW.c_cc[VMIN] = 1;
NEW.c_cc[VTIME] = 0;
ioctl(Keyfile, TCSETA, &NEW);
}
/******************* Start of Main Program ********************/
main()
{
int Bytes;
int Buffer[2];
/*run_expire(); */
InitKeyboard();
do
{
SetRead();
Bytes = read( Keyfile, Buffer, 1 );
ioctl(Keyfile, TCSETA, &OLD);
printf( "Read char %x\n", (short) Buffer[0] );
}
while ( Buffer[0] != 'Z' );
}
More information about the Comp.unix.questions
mailing list