?
Solved

Evaluating keyboard entries

Posted on 2000-03-11
4
Medium Priority
?
238 Views
Last Modified: 2010-04-15
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
0
Comment
Question by:alvinrc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 

Expert Comment

by:nadt
ID: 2609009
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
 

Author Comment

by:alvinrc
ID: 2613523
Adjusted points to 85
0
 

Author Comment

by:alvinrc
ID: 2613524
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
 

Accepted Solution

by:
nadt earned 170 total points
ID: 2614860
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question