• C

Evaluating keyboard entries

I managed to turn off the input buffer on the terminal so i can process one key character at a time.  My question is how can i evaluate the keys (especially the arrow and function) when the user presses them and do a certain action on whatever key is pressed.

We have an AIX Unix.

Thanks
alvinrcAsked:
Who is Participating?
 
nadtConnect With a Mentor Commented:
alvinrc,
Sorry I am not very conversent with unix but I think if i give u an assembly language code containing bios interrupts it should work.  'cause Whatever u're os is whatever language u use it can understand assembly bios interrupts.  Paste this code in any of u're functions like this:-

_asm
{
mov ah,00h;
int 16h;

/*what these two lines will do is that they will invoke bios-interrupt 16h with function 00h which is `get a character from keyboard'

after executing these two lines u will have `ah' containing the scan code (0 or 1) depending on whether spacial character has been pressed or not and `al' will contain the ascii of your interest.  You can write following instruction to validate the same
/*
mov boolean,ah;
mov character,al;

do_validation;
}

This will surely help.
regards
nadt
0
 
nadtCommented:
I think this should work

int readkey(int *function_key)
{
  char tempkey;

  *function_key=0;
  tempkey=getch();
  if (tempkey==0)
  {
     function_key=1;  
     tempkey=getch();
  }
  return(tempkey);
}

you can cut paste this procedure in your program as-is.  What this procedure essentially does is:-

1)  if special key is pressed it returns its ascii number and sets *function_key=1;  prompting you that a special key like arrow or esc has been pressed.  
2)  if normal key is pressed it returns its ascii number and sets *function_key=0;  prompting you that is a normal key has been pressed.  

call this function in your program as:-

int isfunct;
int xyz;
xyz=readkey(&isfunc);


hope this helps,
nadt
0
 
alvinrcAuthor Commented:
Adjusted points to 85
0
 
alvinrcAuthor Commented:
Im using a Unix C, i think the getch() function is for ms dos c, and when i try this

char tempkey
tempkey = getchar()

the tempkey wont come out as zero eventhough
i type in esc or any special chars
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.